Skip to content

Instantly share code, notes, and snippets.

@rotu
Created January 17, 2023 20:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rotu/d5fae84ad32b8fe8bddce42d60405456 to your computer and use it in GitHub Desktop.
Save rotu/d5fae84ad32b8fe8bddce42d60405456 to your computer and use it in GitHub Desktop.
open window and inject module
j = "data:text/javascript,"+encodeURIComponent(`console.log("hello from "+import.meta.url)`)
w = window.open("about:blank")
x1 = await w.eval(`import(${JSON.stringify(j)})`)
x2 = await w.eval(`import(${JSON.stringify(j)})`)
w2 = window.open("about:blank")
y1 = await w2.eval(`import(${JSON.stringify(j)})`)
y2 = await w2.eval(`import(${JSON.stringify(j)})`)
console.assert(x1 === x2)
console.assert(y1 === y2)
console.assert(x1 !== y1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment