Selenium Java + Chrome + ModHeader: Failed to read the 'localStorage' property from 'Window': Access is denied for this document

Viewed 315

I'm willing to set a specific Authorization header value in order to run a Selenium Java test.

To do this, I downloaded the ModHeader extension.

This is how I instanciate my driver:

ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("\\path\\to\\ModHeader.crx"));
driver = new ChromeDriver(options);

And this is how I try to use ModHeader (yup I took this on StackOverflow lol).

driver.get("chrome-extension://idgpnmonknjnojddfkpgkljpfnnfcklj/_generated_background_page.html");
JavascriptExecutor js;
js = (JavascriptExecutor)driver;
js.executeScript("localStorage.setItem('profiles', JSON.stringify([{           " +
            "  title: 'Selenium', hideComment: true, appendMode: '',           " +
            "  headers: [                                                      " +
            "    {enabled: true, name: 'Authorization', value: 'Bearer esldfnWhateverjnfksjd..--', comment: ''}  " +
            "  ],                                                              " +
            "  respHeaders: [],                                                " +
            "  filters: []                                                     " +
            "}]));                                 

However, an error is thrown while running executeScript:

org.openqa.selenium.WebDriverException: <unknown>: Failed to read the 'localStorage' property from 'Window': Access is denied for this document.

I changed my Chrome configuration so that all cookies are allowed, but it didn't change anything.

Any idea?

0 Answers
Related