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

Marked doesn't work with Firefox extension when loaded as content script #1292

Closed
fuweichin opened this issue Jun 15, 2018 · 3 comments
Closed
Labels

Comments

@fuweichin
Copy link

Describe the bug
Marked doesn't work with Firefox extension when loaded as content script, but other UMD-compliant lib like highlight.js does.

To Reproduce
I have a Firefox extension, in manifest.json,

{
  ...
  "content_scripts": [ {
    "matches": [ "http://*/*", "https://*/*" ],
    "js": [ "libs/marked/0.4.0/marked.js", "libs/highlight.js/9.12.0/highlight.pack.js", "content_script.js" ]
  } ],
  ...
}

and in content_script.js,

console.log(window.marked);
console.log(window.hljs);

Load the extension with Firefox DevTools, the console shows window.marked as undefined, while shows window.hljs as an object .

This happens in Firefox extension but not in Chrome extension.

Expected behavior
It works if I modify slightly on marked's UMD code, from original

;(function(root) {
//...
})(this || (typeof window !== 'undefined' ? window : global));

to

;(function(root) {
//...
})(typeof self !== 'undefined' ? self : this);

which is borrowed from UMD template

@styfle
Copy link
Member

styfle commented Jun 20, 2018

Hi @fuweichin
Thanks for reporting this 👍

I checked git blame to see if this has been modified recently but it was actually added in 2012 and basically the same since 09717d7 with one change in 565b4a0 by @Feder1co5oave

Would you like to create a PR to fix this?

@Feder1co5oave
Copy link
Contributor

I believe this is caused by either one of the following:

  1. this does not resolve to the global object in the context used by FuweiChin
  2. window does not resolve to the global object in that context

It seems that it is safer to use self instead of window (I'm wondering about backward compatibility though), because it works in WebWorkers too.
I'm not sure why this is used to export marked, I guess it should resolve to the global object in some environments but I'm not sure which ones.

(Mozilla content scripts should be allowed to access window, so maybe this does not resolve to it.
Also there's this bug.

@UziTech
Copy link
Member

UziTech commented Dec 4, 2019

I believe this has been fixed by rollup. if this is still an issue feel free to reopen.

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

No branches or pull requests

4 participants