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

Cannot invoke functions from a JavaScript file with <script type="module" src="xx"/> #2304

Open
CptGuo opened this issue Dec 18, 2024 · 0 comments

Comments

@CptGuo
Copy link

CptGuo commented Dec 18, 2024

(Please fill out the issue template with your details)

Expected Behavior

The behavior of JavaScript methods can be rewritten.

Actual Behavior

If the JavaScript is imported with type=module, it cannot be referenced or rewritten, Removing type=module allows it to be referenced and rewritten.
Code example:<script type="module" src="testjs.js"/>

jscode:
function testfun1() {
alert(1111);
}

Specifications

  • Chromium: ( 131.0.6778.85)
  • TM: (i.e. 5.3.2)
  • OS: (i.e. linux ubntu)

Script

(Please give an example of the script if applicable.)

// ==UserScript==
// @name MyName
// @namespace http://mywebsite.com
// @Version 1.0
// @description try to take over the world!
// @author Me
// @match http://mywebsite.com/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @include https://mywebsite.com/*
// @grant none
// ==/UserScript==

window.addEventListener('load', () => {
var fun = window.testfun1;
alert(fun); //Allways alert undefine
});

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

No branches or pull requests

1 participant