I've been using this to allow flash for chrome version 69.
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);
Now on version 71 of chrome, this experimental feature (EphemeralFlashPermission) has been removed.
I've also tried to use these settings but it didn't work as well.
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);
Is there any other way now to enable flash using chromedriver?
答案 0 :(得分:8)
我还没有找到任何选择,恐怕永远找不到。
Windows的解决方法是使用组策略(通过向注册表添加条目):
reg add HKLM\Software\Policies\Google\Chrome /v DefaultPluginsSetting /d 1 /t REG_DWORD /f
reg add HKLM\Software\Policies\Google\Chrome\PluginsAllowedForUrls /v 1 /d http://* /t REG_SZ /f
reg add HKLM\Software\Policies\Google\Chrome\PluginsAllowedForUrls /v 2 /d https://* /t REG_SZ /f
或仅创建带有.reg扩展名的文件,然后在其中添加以下文本:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google]
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]
"DefaultPluginsSetting"=dword:00000001
[HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome\PluginsAllowedForUrls]
"1"="http://*"
"2"="https://*"
然后保存并双击该文件。
答案 1 :(得分:0)
我对此的小解决方法,例如@doctordrue;)
from winreg import *
import sys
reg_path = 'Software\Policies\Google\Chrome\PluginsAllowedForUrls'
allow_flash = {'1': 'https://url'}
if sys.platform == 'win32':
try:
try:
RegistryKey = OpenKey(HKEY_LOCAL_MACHINE, reg_path, 0, KEY_ALL_ACCESS)
for K,V in allow_flash.items():
try:
if QueryValueEx(RegistryKey, K)[0] == V: pass
else:
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
except FileNotFoundError:
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
CloseKey(RegistryKey)
except FileNotFoundError:
RegistryKey = CreateKey(HKEY_LOCAL_MACHINE, reg_path)
for K, V in allow_flash.items():
SetValueEx(RegistryKey, K, 0, REG_SZ, V)
CloseKey(RegistryKey)
except:
# write_in_log(traceback.format_exc())
pass