1

1. Is object URL cached?

Testing in the same context, object URL was still avialable after URL.revokeObjectURL().

(async () => {
  const str =
`export class Hi {
  static log() {
    console.log('Hello there!');
  }
}`;

  const blob = new Blob([str], {type: 'text/javascript'});
  const url = URL.createObjectURL(blob);
  console.log(blob);  // Blob { size: 73, type: "text/javascript" }
  console.log(url);   // blob:null/92bfa492-...

  const {Hi} = await import(url);
  console.log(Hi);    // class Hi {}
  Hi.log();           // Hello there!

  URL.revokeObjectURL(url);

  // test after delay
  for (let i = 1; i < 4; i++) {
    const n = 10*i;
    setTimeout(async () => {
      console.log(`After ${n} seconds`);
      const obj = await import(url);
      console.log(Hi);    // class Hi {}
      Hi.log();           // Hello there!
    }, n*1000);
  }

})();

2. Is URL.revokeObjectURL() tied to a context?

Can an object URL created in the background (or action popup) script and passed to the content script, be revoked in the content script?

Update

See also:

erosman
  • 7,094
  • 7
  • 27
  • 46
  • 1) The blob back-end store is global, so it must be maintained by the browser process, which means revocation happens asynchronously, after your `import`. If you add a timeout first the import should presumably fail. 2) You can revoke it in a different part of the extension. – wOxxOm May 24 '23 at 17:19
  • @wOxxOm Thank you. I tested it now with 3 timeouts 10, 20, 30 seconds and the imports were successful!! (in both Chrome & Firefox) – erosman May 24 '23 at 18:47
  • Updated the test code. – erosman May 24 '23 at 19:11
  • It might be a bug in one browser or maybe it's just not mentioned in the specification that the revoked blob is still kept available as long as there is at least one running JS context of the blob creator's URL origin. – wOxxOm May 25 '23 at 05:18

0 Answers0