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

In API Dynamic mode, @noframes is not working #2170

Open
jb222 opened this issue Sep 5, 2024 · 6 comments
Open

In API Dynamic mode, @noframes is not working #2170

jb222 opened this issue Sep 5, 2024 · 6 comments

Comments

@jb222
Copy link

jb222 commented Sep 5, 2024

First off, the new Userscripts API Dynamic mode is amazingly fast. So, to prevent errors, a DOMContentLoaded eventlistener was necessary. The userscript logs DOMContentLoaded even before the content script does! 👍
It would be great if we could set the mode per script, e.g. with something like // @dynamic_mode.

Install the script. Navigate to my test. Open the console.
The web page includes a (same-origin) page in the iframe.

Expected Behavior

The userscript should only work in the parent window, not in the iframe.

Actual Behavior

Unlike Userscripts API mode, in Userscripts API Dynamic mode the <p> is appended to parent AND child window.

Specifications

  • Chromium: (i.e. 128.0.6613.115)
  • TM: (i.e. 5.3.6208)
  • OS: (i.e. MacOS 14.6.1)

Script

// ==UserScript==
// @name         Dynamic Mode Test
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @noframes
// @match        *://*.torporama.com/tm/*
// @run-at       document-start
// ==/UserScript==

(function() {
    'use strict';

    console.log("userscript started...");
    document.addEventListener("DOMContentLoaded", (event) => {
        console.log("DOMContentLoaded, userscript appending element...");
        let el = document.createElement("p");
        el.textContent = "This <p> was appended by the userscript.";
        document.body.appendChild(el);
    });
})();
@derjanb derjanb added this to the 5.3 milestone Sep 5, 2024
@derjanb derjanb added the bug label Sep 5, 2024
@derjanb
Copy link
Member

derjanb commented Sep 5, 2024

I can reproduce the issue...

@derjanb
Copy link
Member

derjanb commented Sep 5, 2024

Should be fixed at 5.3.6209 (crx)

Please download the crx file linked above and drag and drop it to the extensions page chrome://extensions (after you've enabled 'Developer Mode').

For a quick fix please export your settings and scripts as zip or (JSON) file at the "Utilities" tab and import it back at the fixed BETA version.

@jb222
Copy link
Author

jb222 commented Sep 6, 2024

Thanks for the quick fix, it's working now as expected.
Only in API mode, the console shows content: DOMContentLoaded and content: load twice. Is the event triggered by both parent and child windows?

Scherm­afbeelding 2024-09-06 om 10 08 32

@derjanb
Copy link
Member

derjanb commented Sep 6, 2024

Is the event triggered by both parent and child windows?

Yes, the "content" script is injected into every frame at the moment. This needs further improvement.

@jb222
Copy link
Author

jb222 commented Sep 6, 2024

But apparently not in API Dynamic mode.
Thanks!

@derjanb
Copy link
Member

derjanb commented Sep 6, 2024

But apparently not in API Dynamic mode.

Ah, I see. Actually in both modes, but in "UserScripts API Dynamic" all script information is present at real document start and therefore all processing is stopped if no script is supposed to run. In "UserScript API" mode the content script has to wait for the background worker to answer and therefore continues processing until the script information arrived.

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

2 participants