-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Some problems about global #362
Comments
This is exactly what |
You can |
Houston we've got a problem. Could be an old one. // ==UserScript==
// @name Sandbox bug
// @include *
// @grant GM_getValue
// ==/UserScript==
foo = "123";
try { console.log(require); } catch(e) { console.log('require is not defined'); }
|
It's "by-design" because there is no way in JavaScript and with the currently usable APIs to catch such global variable declarations. But this can be solved by the userscripts:
|
Currently I added a |
@eight04, I think you should use |
Indeed, using "var" also is a valid solution. |
Browserify uses a strategy similar to:
, to detect "require" in current scope. I guess I have to make a custom build. |
browserify and other web-related stuff doesn't account for the use case of sandboxed scripting environment running alongside the web page. |
I have no chance to check if it is working at the moment, but you can try to require another script first, that does nothing else than to declare a variable "require" at the current scope? |
I can confirm that this method works. It also works if I put the new require script (the script declaring the "require" variable) AFTER linkify-plus-plus-core. |
I was the one that reported this bug to @eight04 in his awesome linkify. Just caught up on this thread and have to say you guys absolutely rock in how quickly you drilled down to the root cause on this one! I was trying to debug it myself and just am not nearly the JS guru that you guys are, so thank you! |
TamperMonkey cannot access global variables like we normally can in javascript so this commit is working around that restriction by setting all the "global" variables on the window object since that is globally accessible. See this comment on the TamperMonkey GitHub for reference: Tampermonkey/tampermonkey#362 (comment)
Someone reported that Linkify Plus Plus makes disqus fail to load. I found that it is because browserify would assign a
require
to global, and conflict with disqus. Here is an userscript to illustrate what happened (try it on this page):So, it seems that userscript share the same global with page script. Is it by-design or a bug?
The text was updated successfully, but these errors were encountered: