Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Allow Flash content in Chrome 69 running via chromedriver

Does anybody know how to enable Flash plugin in Chrome 69. I use chromedriver 2.41 with java selenium bindings. I've tried with

prefs.put("profile.default_content_setting_values.plugins", 1);
prefs.put("profile.content_settings.plugin_whitelist.adobe-flash-player", 1);
prefs.put("profile.content_settings.exceptions.plugins.*,*.per_resource.adobe-flash-player", 1);

but with no luck. I've also tried to compare chrome profile preferences with disallowed/allowed flash for particular site and then tried with:

            Map<String, Object> site = new HashMap<>();
            Map<String, Object> values = new HashMap<>();
            Map<String, Object> setting = new HashMap<>();
            setting.put("flashPreviouslyChanged", true);
            values.put("last_modified", "13180613213099316");
            values.put("setting", setting);
            site.put("http://my.site,*", values);
            prefs.put("profile.content_settings.exceptions.flash_data", site);

but it won't work as well.

I've also tried to run with profile specified via

options.addArguments("user-data-dir=" + profileDir);

but since this white list setting becomes 'ephemeral' in Chrome 69 it also won't work.

Is there any method to run my automation in Chrome with flash support?

like image 317
doctordrue Avatar asked Sep 05 '18 12:09

doctordrue


4 Answers

Thanks everyone for answers.

I finally have found the solution. In order to enable flash progrmatically since Chrome 69 we have to do 2 things:

  1. Disable Ephemeral Flash Permissions (to enable list of allowed for Flash sites) and
  2. Add all sites to that list.

See the following code on Java:

ChromeOptions options = new ChromeOptions();
// disable ephemeral flash permissions flag
options.addArguments("--disable-features=EnableEphemeralFlashPermission");
Map<String, Object> prefs = new HashMap<>();
// Enable flash for all sites for Chrome 69
prefs.put("profile.content_settings.exceptions.plugins.*,*.setting", 1);

options.setExperimentalOption("prefs", prefs);
nestedDriver = new ChromeDriver(options);
like image 168
doctordrue Avatar answered Nov 17 '22 11:11

doctordrue


Given the flag --disable-features=EnableEphemeralFlashPermission has been removed in Chrome 71 which severely cripples Flash test automation I would like to share our solution.

public class FlashPolicyHelper {

    private final ChromeDriver driver;

    public FlashPolicyHelper(ChromeDriver driver) {
        this.driver = driver;
    }

    public FlashPolicyHelper addSite(String site) {
        this.driver.get("chrome://settings/content/siteDetails?site=" + site);
        WebElement root1 = driver.findElement(By.tagName("settings-ui"));
        WebElement shadowRoot1 = expandRootElement(root1);
        WebElement root2 = shadowRoot1.findElement(getByIdentifier("id=container"));
        WebElement main = root2.findElement(getByIdentifier("id=main"));
        WebElement shadowRoot3 = expandRootElement(main);
        WebElement shadowRoot4 = shadowRoot3.findElement(getByIdentifier("class=showing-subpage"));
        WebElement shadowRoot5 = expandRootElement(shadowRoot4);
        WebElement shadowRoot6 = shadowRoot5.findElement(getByIdentifier("id=advancedPage"));
        WebElement shadowRoot7 = shadowRoot6.findElement(By.tagName("settings-privacy-page"));
        WebElement shadowRoot8 = expandRootElement(shadowRoot7);
        WebElement shadowRoot9 = shadowRoot8.findElement(getByIdentifier("id=pages"));
        WebElement shadowRoot10 = shadowRoot9.findElement(By.tagName("settings-subpage"));
        WebElement shadowRoot11 = shadowRoot10.findElement(By.tagName("site-details"));
        WebElement shadowRoot12 = expandRootElement(shadowRoot11);
        WebElement shadowRoot13 = shadowRoot12.findElement(By.id("plugins"));
        WebElement shadowRoot14 = expandRootElement(shadowRoot13);
        new Select(shadowRoot14.findElement(By.id("permission"))).selectByValue("allow");
        return this;
    }

    private By getByIdentifier(String identifier) {
        String[] identifiers = identifier.split("=");

        return identifiers[0].equals("id") ? By.id(identifiers[1]) :
                By.className(identifiers[1]);
    }

    private WebElement expandRootElement(WebElement element) {
        return (WebElement) driver.executeScript("return arguments[0].shadowRoot",element);
    }
}

The helper should be called after instantiating the ChromeDriver.

 driver = new ChromeDriver(options);
 new FlashPolicyHelper(driver).addSite("https://your.site").addSite("https://another.site");
like image 36
Johno Crawford Avatar answered Nov 17 '22 09:11

Johno Crawford


Follow these steps:

  1. Input this URL in Chrome: chrome://flags/
  2. On search inputbox, digit: ephemeral flash
  3. Choose "disabled" option.

This will not ask to run Flash Player for further sessions in Chrome 69.

like image 2
Rodolpho Silva Avatar answered Nov 17 '22 09:11

Rodolpho Silva


Python3 version for Chrome 74. Converted from the Java version of @JohnoCrawford above.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select

def add_flash_site(driver, web_url):
    def expand_root_element(element):
        return driver.execute_script("return arguments[0].shadowRoot", element)

    driver.get("chrome://settings/content/siteDetails?site=" + web_url)
    root1 = driver.find_element(By.TAG_NAME, "settings-ui")
    shadow_root1 = expand_root_element(root1)
    root2 = shadow_root1.find_element(By.ID, "container")
    root3 = root2.find_element(By.ID, "main")
    shadow_root3 = expand_root_element(root3)
    root4 = shadow_root3.find_element(By.CLASS_NAME, "showing-subpage")
    shadow_root4 = expand_root_element(root4)
    root5 = shadow_root4.find_element(By.ID, "advancedPage")
    root6 = root5.find_element(By.TAG_NAME, "settings-privacy-page")
    shadow_root6 = expand_root_element(root6)
    root7 = shadow_root6.find_element(By.ID, "pages")
    root8 = root7.find_element(By.TAG_NAME, "settings-subpage")
    root9 = root8.find_element(By.TAG_NAME, "site-details")
    shadow_root9 = expand_root_element(root9)
    root10 = shadow_root9.find_element(By.ID, "plugins")
    shadow_root10 = expand_root_element(root10)
    root11 = shadow_root10.find_element(By.ID, "permission")
    Select(root11).select_by_value("allow")
like image 2
BaiJiFeiLong Avatar answered Nov 17 '22 09:11

BaiJiFeiLong