我有:
Chrome扩展程序可以在无头模式下工作吗?
此线程从2016年开始: https://bugs.chromium.org/p/chromium/issues/detail?id=604324
这是2017年的版本:https://bugs.chromium.org/p/chromedriver/issues/detail?id=2071
这两篇文章建议 chromedrive不支持带有扩展功能的无头模式? 这仍然是真的吗? Firefox的扩展确实支持无头……
请注意,我不想为个人资料分配ops.add_argument('user-data-dir=path_to_profile')
。这应该允许解决方案。但是我需要在线程中工作的解决方案...而无需手动将配置文件复制和分配给每个线程。
这是我的代码:
import selenium
from selenium.webdriver.chrome.options import Options as options
from selenium.webdriver.chrome.service import Service
#///////////////// Init binary & driver
new_binary_path = 'D:/path/Selenium_Test/chrome/chrome_exe/installed _32/chrome.exe'
new_driver_path = 'D:/path/Selenium_Test/chrome/chromedriver77_32.exe'
new_addon_path = r'D:\path\Selenium_Test\chrome\chrome_exe\uBlock.crx'
#///////////////// Init headless
serv = Service(new_driver_path)
ops = options()
ops.binary_location = new_binary_path
ops.add_argument("--headless")
#ops.headless = True (TRIED THIS -- doesnt work)
ops.add_extension(new_addon_path)
#ops.add_argument("--load-extension="+new_addon_path) (TRIED THIS -- doesnt work)
#///////////////// Init Browser
print('establishing 1st browser...')
browser1 = selenium.webdriver.Chrome(service=serv, options=ops)
browser1.set_page_load_timeout(int(load_page_timeout))
堆栈跟踪:
selenium.common.exceptions.WebDriverException: Message: unknown error: failed to wait for extension background page to load: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
from unknown error: page could not be found: chrome-extension://cjpalhdlnbpafiamejdnhcphjbkeiagm/background.html
Stacktrace:
Backtrace:
Ordinal0 [0x003FEB13+1501971]
Ordinal0 [0x0037F6D1+980689]
Ordinal0 [0x0030765F+489055]
Ordinal0 [0x002F84FA+427258]
Ordinal0 [0x0029C0D0+49360]
Ordinal0 [0x002B9800+169984]
Ordinal0 [0x002B942D+169005]
Ordinal0 [0x002B78EB+162027]
Ordinal0 [0x002A0AC7+68295]
Ordinal0 [0x002A1B40+72512]
Ordinal0 [0x002A1AD9+72409]
Ordinal0 [0x00398F37+1085239]
GetHandleVerifier [0x0049D7ED+503293]
GetHandleVerifier [0x0049D580+502672]
GetHandleVerifier [0x004A46AC+531644]
GetHandleVerifier [0x0049DFFA+505354]
Ordinal0 [0x00390606+1050118]
Ordinal0 [0x0039047F+1049727]
Ordinal0 [0x0039AF9B+1093531]
Ordinal0 [0x0039B103+1093891]
Ordinal0 [0x0039A095+1089685]
BaseThreadInitThunk [0x76806359+25]
RtlGetAppContainerNamedObjectPath [0x77427B74+228]
RtlGetAppContainerNamedObjectPath [0x77427B44+180]
谢谢