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

[Firefox] Consider to use (programmatic) content scripts API #523

Closed
kekkc opened this issue Mar 18, 2018 · 11 comments
Closed

[Firefox] Consider to use (programmatic) content scripts API #523

kekkc opened this issue Mar 18, 2018 · 11 comments

Comments

@kekkc
Copy link

kekkc commented Mar 18, 2018

Current implementation of tabs.executeScript() causes many problems, e.g. no proper run-at document-start support.

Any plans to use the new, preferred Content scripts API?
https://developer.mozilla.org/en-US/Add-ons/WebExtensions/Content_scripts
https://bugzilla.mozilla.org/show_bug.cgi?id=1332273

@kekkc kekkc changed the title Use Content scripts API Use Content scripts API (Firefox) Mar 18, 2018
@derjanb
Copy link
Member

derjanb commented Mar 18, 2018

Current implementation of tabs.executeScript() causes many problems, e.g. no proper run-at document-start support.

Tampermonkey doesn't use tabs.executeScript and you can enforce proper document-start support by setting "Inject Mode" to "Instant". Do you know other problems?

Any plans to use the new, preferred Content scripts API?

I'l check that once it's clear that the current @include and @match syntax can be supported.
https://bugzilla.mozilla.org/show_bug.cgi?id=1445909

@derjanb derjanb changed the title Use Content scripts API (Firefox) [Firefox] Consider to use (programmatic) content scripts API Mar 18, 2018
@kekkc
Copy link
Author

kekkc commented Mar 18, 2018

Tampermonkey doesn't use tabs.executeScript and you can enforce proper document-start support by setting "Inject Mode" to "Instant". Do you know other problems?

Mostly that the current implementation doesn't work reliably for document-start. E.g. I use the following script:
`// ==UserScript==
// @name No Events
// @author Sacharja
// @Version 1.3.0
// @description Disables annoying events
// @namespace sacharja
// @run-at document-start
// ==/UserScript==

function clearEventPROX(a) {
if (!a) return;
a.opener = cloneInto(null, a);
}
if (unsafeWindow) clearEventPROX(unsafeWindow);`

When I go to https://mathiasbynens.github.io/rel-noopener/ I can click "Click me!!1 (same-origin)", close the opened tab and go back to first one and it's not changed (the script is working via the instant setting). However, if I reload the tab then, click again on "Click me!!1 (same-origin)" & close the opened tab, the original one is changed (message "hacked...").

Whatever workaround is used by TM to inject scripts instantly, it's not guaranteed for 100% that the script will always execute at document-start.

@derjanb
Copy link
Member

derjanb commented Mar 18, 2018

@kekkc Thanks for that example. It's working reliably at Chrome, but at Firefox Tampermonkey sometimes seems to run after the (inline) page scripts were executed. I'll check that.

@kekkc
Copy link
Author

kekkc commented Mar 18, 2018

Don't invest too much time, it's a known FF bug and the reason behind Content scripts API ;) Currently there seems to be no other way in FF to reliably run at document-start.
https://bugzilla.mozilla.org/show_bug.cgi?id=1189770
greasemonkey/greasemonkey#1849

@derjanb
Copy link
Member

derjanb commented Mar 18, 2018

I discovered at least one way: add a break-point to an inline script and the issue will never happen. 🙄

@derjanb
Copy link
Member

derjanb commented Mar 18, 2018

@kekkc The problem is that Tampermonkey uses a "document_start" content_script which is defined at manifest.json, but I do see the page scripts running before. If this doesn't work, then also any other dynamically defined programmatic content script is not guaranteed to run before the page scripts, right?

@tophf
Copy link

tophf commented Mar 18, 2018

I do see the page scripts running before.

Firefox implementation of WebExtensions API still has many bugs in its core parts so it wouldn't surprise me if this is yet another one.

@derjanb
Copy link
Member

derjanb commented Mar 18, 2018

Sorry. I was in the wrong movie! It's just https://bugzilla.mozilla.org/show_bug.cgi?id=1376932 🙄
I'll use the workaround to make instant injection work reliably at the next beta.

@derjanb
Copy link
Member

derjanb commented Mar 19, 2018

@kekkc The issue is fixed at 4.6.5741beta

@kekkc
Copy link
Author

kekkc commented Mar 22, 2018

Pretty cool, thx for the quick fix ;)

@derjanb
Copy link
Member

derjanb commented Jun 22, 2022

The issue is fixed at 4.6.5741beta

@derjanb derjanb closed this as completed Jun 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants