Open loynoir opened 2 years ago
unsafeWindow is not defined
seems import()
context have no GM_XXX
and unsafeWindow
Here it works:
// ==UserScript==
// @name New Userscript
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match https://unpkg.com/
// @icon https://www.google.com/s2/favicons?domain=github.com
// @grant GM_download
// @grant GM.download
// ==/UserScript==
import("https://unpkg.com/@popperjs/core@2").then((test) => {
console.log(GM_info);
console.log(GM.info);
console.log(GM_download);
console.log(GM.download);
console.log(unsafeWindow);
});
But with @grant none
, the unsafeWindow
indeed isn't defined, but it should so if I remember right.
And with dynamic import, it is very easy to face up with CSP.
@7nik Oh, I mean import() context
to something like
// foobar.user.js
// @grant GM_download
// @grant GM.download
import('https://cors.selfhosted/dep.mjs')
// Feature Request
importShim('https://cors.selfhosted/dep.mjs')
// dep.mjs
// not defined
console.log(GM.download)
Modules are executed in their own contexts. Thus they can define root variables without exposing them to everybody. But here they go out of TM's context as well.
Is it possible to have ESM style importShim(dependency)?