Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

cannot enable Flash by default. neither firefox or chrome #497

Closed
Shinoby1992 opened this issue Mar 24, 2018 · 11 comments
Closed

cannot enable Flash by default. neither firefox or chrome #497

Shinoby1992 opened this issue Mar 24, 2018 · 11 comments

Comments

@Shinoby1992
Copy link

Please make sure that you provide enough information for us to help you with this issue. Thank you!

Zalenium Image Version(s):
latest
Docker Version:
latest
If using docker-compose, version:
latest
OS:
OSX High Sierra (latest macosx)
Docker Command to start Zalenium:
docker run --rm -ti --name zalenium -p 4444:4444 -e DOCKER=17.06.2-ce -v /var/run/docker.sock:/var/run/docker.sock -v /tmp/videos:/home/seluser/videos --privileged dosel/zalenium start --videoRecordingEnabled false --desiredContainers 0 --timeZone "Europe/Berlin" --screenWidth 1280 --screenHeight 673

Expected Behavior -

chrome/firefox enabled flash

Actual Behavior -

in firefox activate flash message
in chrome activate flash message and "restart chrome to enable flash" in the left corner

I cannot enable flash in chrome or in firefox
my python code does connect with webdriver.remote
i tried everything out i cannot solve this issue not with firefox, or with chrome

running my python code locally just with webdriver.Firefox or webdriver.Chrome does work:

i use this one locally and is enough for firefox having flash enabled
#profile = webdriver.FirefoxProfile()
#profile.set_preference('plugin.state.flash', 2)

@diemol
Copy link
Contributor

diemol commented Mar 28, 2018

Hi @Shinoby1992,

Could you please share the code you use to do that? I've never tried it before, but we can double check.

@Shinoby1992
Copy link
Author

Okay easy way here is a code.
I can't enable Flash via Remote Driver, the same goes for PulseAudio.
But what i could do is, creating a own dockerfile with my python script
that dockerfile include firefox, chrome + a 3 liner to install Flash in my ubuntu system.

Now my second big question btw ... like in this situation i am now, i tried now 2 days to edit the dockerfile and create my custom zalenium build with
-> 3 liner installing flash
-> install pulse audio
-> copy my script in
what ever i do i tried it out in different ways, (edit dockerfile, create a dockerfile and use FROM dosel/zalenium as the base image and then some custom code, but it don't work i can't accomplish that

#!/usr/bin/env python
from selenium import webdriver
import time
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.options import Options

def remotechromev1():
    global driver
    global url
    #REMOTE CHROME V1 
    #THIS ONE DOES SHOW ON BROWSERCHECK THAT FLASH IS ACTIVATE BUT STILL REAL FLASH CONTENT DOES NOT WORK!
    options = webdriver.ChromeOptions()
    options.add_argument('--no-sandbox')
    options.add_argument('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0')
    prefs = {
        "RunAllFlashInAllowMode":"true",
        "profile.default_content_settings.state.flash":1,
        "profile.plugins.flashBlock.enabled": 0,
        "profile.default_content_setting_values.plugins": 1,
        "DefaultPluginsSetting": 1,
        "AllowOutdatedPlugins":1,
        "profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
        "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
        "PluginsAllowedForUrls": "https://mono-1.com/monoface/main.html"
    }
    options.add_experimental_option("prefs",prefs)
    driver = webdriver.Remote(command_executor = url,desired_capabilities=options.to_capabilities())
def remotefirefoxv1():
    global driver
    global url
    #REMOTE FIREFOX V1 
    profile = webdriver.FirefoxProfile()
    profile.set_preference('plugin.state.flash', 2)
    profile.set_preference('general.useragent.override', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:59.0) Gecko/20100101 Firefox/59.0')
    profile.set_preference('dom.ipc.plugins.enabled.libflashplayer.so','true')
    options = Options()
    driver = webdriver.Remote(options=options,command_executor = url, desired_capabilities=webdriver.DesiredCapabilities.FIREFOX,browser_profile=profile)
def main():
    global driver
    global url
    url = "http://localhost:4444/wd/hub"
    
    #TEST WITH CHROME OR WITH FIREFOX
    #remotechromev1()
    remotefirefoxv1()
    
    driver.set_window_size(1280, 673)
    driver.delete_all_cookies()
    #WEBSITE FOR PULSE AUDIO ERROR
    #print "Pulse Error if you Start the documentary message is Pulse Audio is not installed"
    #driver.get('http://cloudsovercuba.com')
    #time.sleep(60)
    #WEBSITE NOT LOADING WHEN NO FLASH IN SYSTEM INSTALLED
    print "Flash Test only visible if Flash is installed and active"
    driver.get('https://mono-1.com/monoface/main.html')
    time.sleep(60)
    #FLASH HAS TO GET HERE LISTED
    print "Control Flash has to be here listed"
    driver.get('http://www.browsercheck.pcwelt.de/de/flash-check')
    time.sleep(100)

main()

@Shinoby1992
Copy link
Author

if you need more information let me know i still couldn't solve my issue , i even tried already existing docker images with pulse audio and browsers installed and tried to use the dockerfile as a template to add codes to zelenium dockerfile and custom build it but somehow this does not work...

greetings from dortmund

@diemol
Copy link
Contributor

diemol commented Apr 2, 2018

Hi @Shinoby1992,

Sorry for the delay, Easter holidays :)

Could you please share your modified dockerfile please?

Greetings from Berlin!

@Shinoby1992
Copy link
Author

Shinoby1992 commented Apr 8, 2018

Sorry i had to reproduce everything, but still i cannot solve my problems
my dockerfile im using adding these lines

RUN apt-get update
RUN apt-get install -y python2.7 python-pip python2.7-dev python-lxml libxml2-dev libxslt1-dev
RUN apt-get install -y libgconf2-4 libnss3-1d libxss1
RUN apt-get install -y fonts-liberation libappindicator1 xdg-utils
RUN apt-get install -y software-properties-common
RUN apt-get install -y curl
RUN sudo sh -c 'echo "deb http://archive.canonical.com/ubuntu trusty partner" >>/etc/apt/sources.list'
RUN sudo apt-get update
RUN sudo apt-get -y install adobe-flashplugin  
# install Requirements for Python Script
RUN pip install selenium
RUN pip install pyvirtualdisplay
RUN pip install BeautifulSoup4
RUN pip install numpy
RUN pip install requests
RUN pip install termcolor
RUN pip install colorama
RUN pip install lxml
COPY Script.py /home/seluser/Script.py
COPY utils.py /home/seluser/utils.py

and then of course making a local snapshot with make

I tried solving my problem with zalenium, with elgalu/selenium, SeleniumHQ/docker-selenium
nothing works. every build really has its own positive and negative thing...
Im here in Zalenium issues so, the real issue now is that
i cannot customize the firefox that gets used, firefox 59 has a Pulseaudio bug that got fixed in Firefox 60 beta , it would be nice if i somehow could customize the firefox version used, in SeleniumHQ/docker-selenium i could easily change the dockerfile and use latest-beta firefox.

The second problem is that enable firefox flash for a website and allow it always somehow does not work.
i run my python script on a server and saw that it does not run there instantly and i had to enable flash manual during the script is running with a mouse click on the "LOCK" symbol on the left of the url adressbar in firefox, just to set "allow flash plugin on this website"
after this manually doing my script does work correctly.
maybe its better to analyse all of the problems and split them in separate questions
thank you for your intend to help im still figuring out because it seems to be more than one problem is the real reason it does not work. Seems like the official Firefox 60 version gets out in the next days so i guess it will be automatically be the latest version using from elgalu/selenium , zalenium

@diemol
Copy link
Contributor

diemol commented Jul 12, 2018

Hi @Shinoby1992,

Sorry for not checking this before. Anyway, what I could see with the latest image of elgalu/selenium is that Chrome can run Flash out of the box and Firefox cannot. For the second case, Flash would need to be installed. I tried that with the first thing I found on the Internet and I created this small Dockerfile:

FROM elgalu/selenium

USER root

RUN echo "deb http://archive.canonical.com/ubuntu xenial partner\n" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y adobe-flashplugin

USER seluser

After that, when I open Firefox, I can run pages with Flash.
image

That is part one of the solution, to have an image that can have Chrome and Firefox running Flash.

The second part is to send the correct capabilities/profile/preferences to Chrome and Firefox so the test can run on the page with Flash enabled. After Googling, I found these links:
https://stackoverflow.com/questions/43376707/how-to-enable-adobe-flash-in-firefox-selenium-webdriver-with-firefoxprofile
https://stackoverflow.com/questions/48468305/enable-flash-with-chromedriver-in-python

So I think it is a matter of trying them in the test and/or researching a bit more how to do it. Please give it a try.

I will close this issue since it is more related on how to build the image with Flash added and also running a test with it, and it is not a Zalenium bug or something like that.

If you need more assistance on running the test with Flash, perhaps you can join us at https://seleniumhq.herokuapp.com/, there is a specific channel for #zalenium and another one for general questions of Selenium and docker-selenium (this one is called #selenium).

@diemol diemol closed this as completed Jul 12, 2018
@DowneyTung
Copy link

@diemol I think this issue is not solved yet. I passed the desired capability for chrome to zalenium remote webdriver like this
` options = webdriver.ChromeOptions()
prefs = {
"profile.default_content_setting_values.plugins": 1,
"profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.,.per_resource.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.,.setting": 1
}

        options.add_experimental_option("prefs", prefs)
        options.add_argument('--disable-features=EnableEphemeralFlashPermission')
        options.add_argument('--disable-infobars')
        with validate_remote_url(settings['remote_url']) as remote_url:
            driver = Webdriver.remote(command_executor=remote_url, desired_capabilities=options.to_capabilities())`

When I navigate to the https://www.whatismybrowser.com/detect/is-flash-installed, the chrome instance did say the flash is installed,
image

However, when I truly navigate to a website that needs flash to load the content, it is asking me to enable the flash by restart the browser.
image
However, you can't really terminate the current browser session. I still tried driver.close(), but when I start a new instance of driver, the test is live in another browser container node.
So my question would be, do we really have a way to bypass enabling flash in the browser without restarting the browser? Or do we have a way to bring down the browser and bring it up again in the same browser container node?

@diemol
Copy link
Contributor

diemol commented Dec 6, 2018

Hi @DowneyTung,

What I did when I replied to this issue was to perform manually the needed actions to enable flash, and then create an image based on those actions. That was already several Chrome versions ago, so probably the same does not work anymore. So the job is now to take the latest image and replay the actions and figure out again what needs to be done, because when we build the images we do not add flash to them, therefore this would need to be added in a new image based on the one we build.

@DowneyTung
Copy link

DowneyTung commented Dec 6, 2018

I used some old version elgalu/selenium (chrome version 64) and build a new docker file with flash plugin installed, but still get the restart chrome to enable adobe flash player info.
Here is my revised dockerfile

FROM elgalu/selenium:3.9.1-p2

USER root

RUN echo "deb http://archive.canonical.com/ubuntu xenial partner\n" >> /etc/apt/sources.list
RUN apt-get update && apt-get install -y adobe-flashplugin

USER seluser

I also passed the desired cap to the webdriver as well...

 options = webdriver.ChromeOptions()
prefs = {
"profile.default_content_setting_values.plugins": 1,
"profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.,.per_resource.adobe-flash-player": 1,
"profile.content_settings.exceptions.plugins.,.setting": 1
}

        options.add_experimental_option("prefs", prefs)
        options.add_argument('--disable-features=EnableEphemeralFlashPermission')
        options.add_argument('--disable-infobars')

And here is how the test looks like when it launches, you can notice, https://www.whatismybrowser.com/detect/is-flash-installed showed flash is installed, and also the flash website also show it is downloading....but after that, it requires a restart of browser to enable flash player.
test

@DowneyTung
Copy link

DowneyTung commented Dec 9, 2018

@diemol I finally figured out the solution for this. Long story short, it might not be a good idea to use a customized profile user --user-data-dir as it will complicate other tests if we keep adding stuff to that customized profile. For example, if each test runs a facebook login, the first test could log in successfully. The second test would actually skip the login process and the user would already be logged in as they are using the same profile.

So I think the solution would be make the chromium use the right version of flash, which is Pepperflashplugin-nonfree in this case.

So, if we don't pass the ppapi to the argument, and chromium setting would looks like this
image

so if I build a new elgalu/selenium images like this and run

FROM elgalu/selenium:latest

USER root

RUN sudo apt-get update && sudo apt-get install -y software-properties-common
RUN sudo apt-get update && sudo add-apt-repository ppa:jonathonf/pepperflashplugin-nonfree
RUN sudo apt update
RUN sudo apt install -y pepperflashplugin-nonfree
RUN sudo update-pepperflashplugin-nonfree --install
RUN sudo apt -y install browser-plugin-freshplayer-pepperflash
USER seluser

docker build -t elgalu/selenium:latest $the_new_dockerfile

The extra step above will install the pepperflashplugin-nonfree to the elgalu/selenium images.
@diemol Is that possible to add this the elgalu/selenium image for next release?

Then I start the zalenium container as usual..

When I run my test, I just need add these options to the test, and the flash would work.

        options = webdriver.ChromeOptions()
        prefs = {
            "profile.default_content_setting_values.plugins": 1,
            "profile.content_settings.plugin_whitelist.adobe-flash-player": 1,
            "profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player": 1,
            "profile.content_settings.exceptions.plugins.*,*.setting": 1
        }

        options.add_experimental_option("prefs", prefs)
        options.add_argument('--disable-features=EnableEphemeralFlashPermission')
        options.add_argument('--disable-infobars')
        options.add_argument("--ppapi-flash-version=32.0.0.101")
        options.add_argument("--ppapi-flash-path=/usr/lib/pepperflashplugin-nonfree/libpepflashplayer.so")

13

@diemol
Copy link
Contributor

diemol commented Dec 11, 2018

That's great @DowneyTung! Thanks for your effort and documenting it here.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants