Closed ndtreviv closed 1 year ago
Can you put a breakpoint in your test code before it crashes, then go to chrome://extensions in the test browser, enable "Developer mode" (top right corner), then click on ModHeader's "background page" link. This should open up the "Console". Can you send me the errors that you see there?
It clicking the background page link doesn't do anything, but there is an error if I click the Update button after enabling Developer Mode (found after clicking around trying to figure out why it wasn't opening the background page):
If I go to here: chrome-extension://jciacimpfapbkckkegdfngcnbdpabaoi/_generated_background_page.html which is where I think the background page should be based on this then I get a blank page.
When I move past the point where it tries to load the header page I get a background page (iframe) link:
That link shows me this:
At this point the background page link is still empty.
Man, I stepped through all that without --headless
on and it all worked 😅
Does it not work in headless mode?
--headless
does not work, but --headless=chrome
should work. Give that a shot.
The plot thickens. If I'm not debugging (ie stepping through it slowly) even without --headless
then it doesn't work. The page gets stuck on the background page and doesn't go any further, I guess because of the error.
I tried --headless=chrome
but no joy. Here's the total set of options:
"--start-maximized",
"--kiosk",
"--headless=chrome",
"--disable-dev-shm-usage",
"--ignore-certificate-errors",
"--disable-blink-features=AutomationControlled",
"--log-level=DEBUG",
"--no-proxy-server",
"--whitelisted-ips",
"--no-sandbox",
"--disable-gpu",
"--disable-software-rasterizer"
Wait...it's enabling developer mode that makes it work. If I don't manually go to chrome://extensions and flick that switch then it doesn't work, headless or not. Do I need another option in my chromedriver usage to make this work?
I am not sure what is going on there. I tried running my example code (https://github.com/modheader/modheader_selenium/blob/main/examples/javawebdriver/ChromeExample.java) with no options and with your options, and they both work just fine.
I am running on Windows though. Not sure if there is something specific to running Chrome webdriver on Mac.
I tried including this to enable developer mode on extensions by default:
Map<String, Object> prefs = new HashMap<>();
prefs.put("extensions.ui.developer_mode", true);
chromeOptions.setExperimentalOption("prefs", prefs);
and it still gets stuck on background page. I'll try and get a screen recording to see if that helps.
Here's a screen recording of it. As you can see, it goes to a page not found error briefly before going to the ModHeader page.
The page I'm trying to get is: http://httpbin.org/get which would show me my headers.
https://user-images.githubusercontent.com/1530653/191596632-47b441fa-4db1-465e-891b-343c06052fbc.mp4
Can you try adding a small delay (maybe 1-2 seconds wait) before navigating to webdriver.modheader.com.
I am guessing what is happening underneath the hood is that the extension is still initializing.
That works now, both without --headless
and with --headless=chrome
.
Thanks! Is there a more elegant way of waiting for the plugin to init other than a hard 2 second wait?
eg: In selenium I could wait for an element on page, for example?
You can try using WebDriverWait until webdriver.modheader.com loads successfully.
On Wed, Sep 21, 2022, 2:58 PM Nathan Trevivian @.***> wrote:
That works now, both without --headless and with --headless=chrome.
Thanks! Is there a more elegant way of waiting for the plugin to init other than a hard 2 second wait?
— Reply to this email directly, view it on GitHub https://github.com/modheader/modheader_selenium/issues/36#issuecomment-1254166308, or unsubscribe https://github.com/notifications/unsubscribe-auth/AGC3PX7XSALLYZXLQ24T4ATV7NSG5ANCNFSM6AAAAAAQSLRPOQ . You are receiving this because you commented.Message ID: @.***>
--headless
does not work, but--headless=chrome
should work. Give that a shot.
--headless=chrome
isn't truly headless.
On the mac, for example, I get another chrome showing up in the app switcher (command-tab). When I use --headless
I don't get that.
I'm worried that this isn't doing what it's supposed to do in my linux-docker environment.
Yeah, it's an issue. EG: https://stackoverflow.com/a/62943578/498391
I'm getting the same error ([SEVERE]: bind() failed: Cannot assign requested address (99)
) on my linux environment when using --headless=chrome
Unfortunately that is beyond my scope. You may want to reach out to Chromium / Selenium for helps on --headless=chrome
. I think --headless
itself will not support installing extensions.
@hao1300 Figured I'd share that I'm running into this issue (ERR_NAME_NOT_RESOLVED
) on MacOS as well, but not running headless. What information would be most useful to troubleshoot? Is the debug crx still valid?
I can remove the (endless retry attempts..) if I revert to the old crx and domain. Seems to start working w/in 1 second, but not always.
driver.get("https://webdriver.modheader.com/add?example=header");
// Try again if the extension wasn't ready:
// https://github.com/modheader/modheader_selenium/issues/36
while (driver.getCurrentUrl().contains("chrome-extension") == false) {
log().info("waiting for modheader_selenium to initialize");
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
driver.get("https://webdriver.modheader.com/add?example=header");
}
// Ensure the headers are loaded before continuing
new WebDriverWait(driver, Duration.ofSeconds(5))
.until(ExpectedConditions.titleIs("Done"));
@abaldwin-op - Did you download the CRX file from here? https://docs.modheader.com/advanced/selenium-webdriver - Click on "Download for Chrome"
When you see the ERR_NAME_NOT_RESOLVED
error, are you able to bring up the ModHeader popup manually? And if so, are you able to modify header manually using ModHeader (without going through the webdriver.modheader.com URL)
@hao1300 - Appreciate the reply.
Odd. That's the one I have in my branch (md5) and it's working without the retry hack.
These are the two I tried before my hack:
What's even more odd is the two CRX above also work now. I added proper URL encoding and a "Done" wait in troubleshooting, so it's possible I didn't catch that I resolved the issue that way...?
We can consider this resolved for now, I think. I'll open a new issue for further troubleshooting if I run into again.
modheader version
I downloaded it from here: https://github.com/modheader/modheader_selenium/raw/main/chrome-modheader/modheader.crx today.
What I expected to happen:
I expected the call to webdriver.modheader.com to be intercepted by the extension and not to get a ERR_NAME_NOT_RESOLVED error.
Code snippet:
Logs: