mozilla / geckodriver

WebDriver for Firefox
https://firefox-source-docs.mozilla.org/testing/geckodriver/
Mozilla Public License 2.0
7.03k stars 1.51k forks source link

"crypto.randomUUID() is not a function" error on a blank tab when running Firefox with geckodriver #2116

Closed IlyaHarlamov closed 1 year ago

IlyaHarlamov commented 1 year ago

System

Testcase

crypto.randomUUUID function is not available when running Firefox 102.11.0esr with geckodriver (reproduced with 0.31.0 and 0.33.0). When trying to call the crypto.randomUUUID function from the browser console, an error "crypto.randomUUID is not a function" is returned. The function is available in the browser when running the browser manually without geckodriver.

whimboo commented 1 year ago

This is actually not related to geckodriver but an issue in Firefox. geckodriver just sets the preference browser.startup.page to 0 so that only a single tab is open with about:blank loaded. And as it looks like this page doesn't allow to use this API.

When I start Firefox normally and set the settings under New Windows and Tabs both to Blank Tab, I can access the API when opening a new tab. But once I explicitly load about:blank in that newly created tab the API is not available anymore.

@smaug---- do you have an idea why that is the case? If it's a bug I'm happy to file it but not sure where exactly right now.

whimboo commented 1 year ago

Note that whenever a real page is loaded the API is available. It's just the blank page which causes the issue, and it is still reproducible in a recent Nightly build.

IlyaHarlamov commented 1 year ago

Hi @whimboo, hmm, I am using Selenide to run the tests, when I open a real page with it, the issue is still there... Not sure how this preference works, or maybe there is any other preference affecting this. I guess something to investigate a bit more

IlyaHarlamov commented 1 year ago

Ok, more information: the "real page" I am opening is hosted on the localhost. For instance, when I open google.com, the API is available, but on the localhost it is not.

UPD:

  1. On the blank page, the issue is reproducible with both regular browser and the one controlled by geckodriver.
  2. On the localhost page, the issue is only reproducible with browser controlled by geckodriver.
smaug---- commented 1 year ago

blank page isn't secure context, and randomUUID() is available on secure contexts only. See [SecureContext] annotation in https://w3c.github.io/webcrypto/#crypto-interface

whimboo commented 1 year ago

Thanks @smaug---- ! Looks like we can close this issue then.