Forum Discussion

JamieRI's avatar
JamieRI
Occasional Contributor
11 months ago

crypto.randomUUID is not a function S @ inject-content-scripts.js:5

FYI: I bumped into an error associated with 1Password Beta extension 8.10.56.22  when I was inspecting a site for an unrelated reason. This is not impacting me, just thought you might like to know. 

Site is http://atecconnectors.com/atec/index.cfm

Chrome Dev console says 

"inject-content-scripts.js:5 Failed to fetch chrome-extension://khgocmkkpikpnmmkgmdnfckapcdkgfaf/inline/injected.js, Import failed 3 times. Final error: crypto.randomUUID is not a function
S @ inject-content-scripts.js:5"

The DevTools AI Assistant added this, which I didn't read but looks interesting:

"Explanation

Okay, let's break down why you're getting the "Failed to fetch ... Import failed 3 times. Final error: crypto.randomUUID is not a function" error and how to fix it.

Understanding the Error

The error message tells us a few critical things:

  • Failed to Fetch: The browser is trying to load a JavaScript file from a Chrome extension ( chrome-extension://khgocmkkpikpnmmkgmdnfckapcdkgfaf/inline/injected.js).
  • Import Failed 3 Times: The browser attempted to load the file three times and failed each time. This suggests the issue is not a temporary network hiccup but something fundamental.
  • crypto.randomUUID is not a function: This is the root cause of the failure. The crypto.randomUUID() method is a relatively new web standard (part of the Web Crypto API) that is used to generate cryptographically secure UUIDs. The browser (or, more likely, the context where this code is running) doesn't support it.

Where the Problem Likely Lies

The problem is most likely in the injected.js file, as the error is complaining about something inside this extension file. Although the error is shown while your web app is working, the problem is not with your app code itself, but rather, the extension injecting this injected.js file.

  • Older Extension Code: The extension is injecting a file that uses crypto.randomUUID(). If the extension was built targeting an older version of Chrome or a different browser that didn't support crypto.randomUUID(), this method may have been added later or not added by the extension authors.
  • Old browser version: An old browser version may not support crypto.randomUUID.

Why Your Web App Code is Involved (Indirectly)

Your web app's code triggers the extension's injection mechanism. Your code doesn't directly use crypto.randomUUID().

Dissecting the Given Code (and How it Relates)

Let's look at the code snippet you provided and see how it contributes to triggering the error, even if it's not causing it:

Code

(l),i.filter(p).forEach(s=>{let u=b();e.addEventListener("DOMContentLoaded",()=>{l(s).then(u.resolve)},{once:!0}),a=[...a,u.promise]})):(`${n}`,a=[...c,...i].filter(p).map(l)),Promise.all(a)},y=()=>{let e=chrome.runtime.getURL(""),t=new URL(e),r=t.protocol,o=t.host;return`${r}//${o}`},m=(e,t)=>{chrome.runtime.sendMessage({name:"report-error",data:{name:"InjectContentScript",message:e,severity:"error",stack:t}})},S=(e,t)=>{if(!h(e)){console.error(t),m(t);return}let r=`${t}, ${e.message}`;console.error(r),m(r,e.stack)},l=async e=>{if(`${n}${e.label}`,e.world==="ISOLATED")try{await C(e.path)}catch(t){return S(t,`Failed to fetch ${e.path}`),Promise.resolve(void 0)}else{let t="Only isolated script injection has been supported";throw m(t),new Error(t)}},C=async e=>{let t=[];try{await T(e);return}catch(i){t.push(i)}await d(25);try{await import(e);return}catch(i){t.push(i)}await d(50);try{await import(e);return}catch(i){t.push(i)}if(t.length===0)throw new Error("Logic error: unreachable code w

Use code snippets with caution

  • Content Script Injection: The code heavily suggests that it's part of a system for dynamically injecting content scripts (scripts that run in the context of a web page) into web pages. This is common for browser extensions.
  • l Function: This is likely the main function for managing the injection of a script. It checks if the target world is "ISOLATED" (a way of running a script in a sandboxed environment).
  • C Function: This is the function that actually attempts to load the script. It tries import() three times, with delays (d(25), d(50)) in between each attempt. The file it tries to import is given in e.path. The error message we are getting is probably coming from this code.
  • chrome.runtime.getURL(): This function is crucial for extensions. It is getting the URL to fetch files from the extension itself. This makes the browser look inside the extension for the injected.js file.
  • Error reporting: The code contains functions m and S which are sending errors to the extension, probably for debug or error tracking purposes.
  • import(e): The repeated import(e) is the exact point where the error happens. When the injected.js is being imported, it uses the crypto.randomUUID, and since it is unsupported, it fails.

Solution and Workarounds

Since the problem is in an external extension file, you cannot directly modify the injected.js code. Your solutions are more about working around the issue or ensuring the extension is updated:

  • Update the Extension:
    • If the extension is from the Chrome Web Store, check if there's an update available. The extension's developer may have fixed this bug.
    • Contact the extension support and report the issue.
  • Find an Alternative Extension:
    • If updating doesn't work or there's no update, see if there's a different extension that offers similar functionality and doesn't have this problem.
  • Polyfill:
    • If the extension is not maintained, a way to avoid the issue could be to implement a polyfill.
    • This polyfill could be injected before the extension's injected.js and would create the crypto.randomUUID if it doesn't exists.
  • Disable the Extension:
    • If you don't need the extension at all, disable it in your browser's extension settings.
  • Use a different browser:
    • An old browser version could be the cause of the issue. Try using a newer browser version.

Important Considerations

  • Security: Be cautious about disabling security-related extensions. Make sure you understand the risks involved.
  • Extension Development: If you are the developer of the extension, replace crypto.randomUUID() by a compatible UUID method or add a polyfill.

In Summary

The error "crypto.randomUUID is not a function" in your scenario means that the injected.js file within the extension is trying to use a feature that's not available in the execution environment. You can fix this by updating or replacing the extension, or by using a polyfill. You must investigate which extension is injecting this file.

Data used to understand this message

Use search instead

AI tools may generate inaccurate info that doesn't represent Google's views. Data sent to Google may be seen by human reviewers to improve this feature. Open settings or learn more

6 Replies

  • Hello JamieRI! 👋

    I'm sorry that you're seeing an unexpected error message in the console when using 1Password. The error message that you've reported matches a known issue that our developers released a fix for in version 8.10.58 of 1Password in the browser which was released back in January. Please update:


    If you still see the issue with the latest version of 1Password then please let me know. 

    -Dave

    !27383

    • Arkkis's avatar
      Arkkis
      New Contributor

      I can still see a similar problem, console says:

      inject-content-scripts.js:5 Failed to fetch chrome-extension://aeblfdkhhhdcdjpifhhbdiojplfjncoa/inline/injected.js, Import failed 3 times. Final error: window.crypto.randomUUID is not a function

      This happens because injected.js tries to call window.crypto.randomUUID().slice(0, 8) without first checking if that exists.

      It does not exist on localhost environment for example, https://developer.mozilla.org/en-US/docs/Web/API/Crypto/randomUUID#:~:text=Secure%20context%3A%20This%20feature%20is%20available%20only%20in%20secure%20contexts%20(HTTPS)%2C%20in%20some%20or%20all%20supporting%20browsers. This makes logging in to a localhost development environment (or any non https page) harder than it should be.

      I was able to bypass this problem in chrome manually by following these steps:

      • open chrome developer tools, navigate to injected.js from the console error
      • enable debugging browser extensions in chrome
      • add a breakpoint to the offending line in injected.js
      • reload the page to rerun the 1password injection script
      • paste the below code snippet to console
      • resume script execution

       

      This script uses the same approach you use elsewhere in injected.js to handle the same problem. To me this seems that in January 8.10.58 you fixed this issue for one use of randomUUID, but either the other use was missed or it was added later.

      window.crypto = window.crypto || {}; window.crypto.randomUUID = window.crypto.randomUUID || (() => { let t = window.crypto || window.msCrypto, r = () => Math.random() * 16; try { if (t && t.randomUUID) return t.randomUUID().replace(/-/g, ""); if (t && t.getRandomValues) r = () => { let n = new Uint8Array(1); return t.getRandomValues(n), n[0]; }; } catch {} return ("10000000100040008000" + 1e11).replace(/[018]/g, n => (n ^ (r() & 15) >> n / 4).toString(16)); });

      Please add a check to your code for all the uses if randomUUID() exists and provides an fallback if it does not.

      Please also add an automated test that checks your code for any new uses of randomUUID that they're handled properly, so that we do not need to come report this in future.

      Thank you, have a nice day!

    • voson's avatar
      voson
      New Contributor

      still error

      Chrome 143.0.7499.170(production) (arm64)

      1password extension 8.11.22.27

    • finwe's avatar
      finwe
      Super Contributor

      Hi Dave,

      I am still seeing the error in Firefox 146, 1Password for Windows 8.11.23 (81123001) and extension 8.11.16.35.

      • voson's avatar
        voson
        New Contributor

        me too,

        Chrome

        143.0.7499.170(production) (arm64)