Skip to content
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

Annotator.Util undefined on pages that define a variable called global #2723

Closed
robertknight opened this issue Nov 15, 2015 · 5 comments · Fixed by #3385
Closed

Annotator.Util undefined on pages that define a variable called global #2723

robertknight opened this issue Nov 15, 2015 · 5 comments · Fixed by #3385

Comments

@robertknight
Copy link
Member

See #2397 (comment) for a minimal repro case of this issue

Launching H via the extension or bookmarklet fails on http://www.thebookseller.com/futurebook/publishing-has-entered-new-and-different-era with a 'cannot read Util of undefined` error or variation on that.

        var Annotator = require("annotator");
        var g = Annotator.Util.getGlobal(); // 'Annotator' is undefined here

I'm sure I investigated something similar before that was related to a site defining its own version of 'global' or something similar.

@robertknight robertknight changed the title Annotator undefined Annotator undefined error on thebookseller.com Nov 15, 2015
@robertknight
Copy link
Member Author

This might be the same issue as #2397 - that page has detailed a detailed investigation.

@robertknight
Copy link
Member Author

Update - yes, this is indeed the issue described in #2397 - the page defines a variable called global which breaks browserify-shim

@robertknight robertknight changed the title Annotator undefined error on thebookseller.com Annotator.Util undefined on pages that define a variable called global Nov 15, 2015
@judell
Copy link
Contributor

judell commented Nov 19, 2015

Closed in favor of #2397.

@judell judell closed this as completed Nov 19, 2015
@robertknight
Copy link
Member Author

@judell - That other issue was closed. This is a more generic issue which supersedes that one. I'm afraid my comment didn't make that clear.

@dwhly
Copy link
Member

dwhly commented Mar 21, 2016

robertknight added a commit that referenced this issue May 30, 2016
Modules which assume the existence of a global variable called "global"
(which exists in Node) are wrapped by Browserify during the build which
normally results in "global" being aliased to "self" or "window" in a
browser environment.

If code on the page into which H is loaded defines a global variable
called "global" however, that gets used instead and this can break such
modules. In the case of https://www.civilsprep.com, "global" is a
reference to a DOM node for example.

This commit fixes the issue by only aliasing "global" (as seen by the
module using it) to either "window" or "self" and not to any existing
variable called "global".

Fixes #2723
nickstenning pushed a commit that referenced this issue Jun 1, 2016
Modules which assume the existence of a global variable called "global"
(which exists in Node) are wrapped by Browserify during the build which
normally results in "global" being aliased to "self" or "window" in a
browser environment.

If code on the page into which H is loaded defines a global variable
called "global" however, that gets used instead and this can break such
modules. In the case of https://www.civilsprep.com, "global" is a
reference to a DOM node for example.

This commit fixes the issue by only aliasing "global" (as seen by the
module using it) to either "window" or "self" and not to any existing
variable called "global".

Fixes #2723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants