I ended up customizing a modify headers extension for chrome (https://chrome.google.com/webstore/detail/modheader/idgpnmonknjnojddfkpgkljpfnnfcklj?hl=en) so it loads a set of header rules for my environment by default, stripped out the unneeded functionality.
When I start chromeDriver, I load that extension to load from my local repo using (--load-extension=${extensionDirFullPath}).
One roadblock I found was I have to
1. load the extension page (using chrome-extension:://${extensionID}/page
).
2. Load another web page (I just use google).
Part of this is just waiting for the extension to load fully, but a wait (even a long one) is not sufficient to ensure that the extension loads and is used. strange stuff.
Also, because I'm loading the extension from a local folder rather than the chrome store, it loads with a different id on my grid node machine than from my local, and different again on my co-workers local. So in my BeforeAllTests, I threw this in:
browser.url('chrome://extensions/');
browser.pause(500);
let extFrame = browser.element('div#extensions iframe');
extFrame.waitForExist(30000);
let extFrameID = extFrame.value;
browser.frame(extFrameID);
browser.click('#toggle-dev-on');
browser.pause(500);
extensionID = browser.element(`//div[@class='extension-details']//h2[text()='${extensionName}']/../../div[@class='developer-extras']/div/span[@class='extension-id']`).getText();
browser.frame();
To get the id of the extension dynamically.
This is roughly the beforeSuite code to load the extension page and google:
browser.url(`chrome-extension://${extensionID}/popup.html`);
browser.pause(500);
browser.url('https://www.google.com');
When I get around to Firefox, it looks like there are several Modify Headers add-ons, which combined with using its own profile should work, with less code than this chrome solution.
Welp, I found a solution that works, but feels ugly and smells like bad code:
Each new browser session (depending on whether you are using a new session per suite or per test or whatever):
-Load a resource from the image server using the basic auth in the before Suite/Test/Whatever method.
-Load your base URL and proceed running the test/suite/whatever like before.
it works, but is kind of ugly.