Skip to content

Adding a script to pages before running WPT Tests #52637

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

Open
luccasjscrambler opened this issue May 19, 2025 · 1 comment
Open

Adding a script to pages before running WPT Tests #52637

luccasjscrambler opened this issue May 19, 2025 · 1 comment

Comments

@luccasjscrambler
Copy link

luccasjscrambler commented May 19, 2025

Hey,

I'm testing a script added to the page to check if this script impacts the browser's functions.

That script that does asynchronous things, and I need to wait for the script to happen before the tests are run.
The problem is that the tests run before the script has completely finished running.

Is there any way to wait for this script to run completely before running the tests?
The solution must be dynamic to work on multiple WPT pages, how can I do it? Is it possible?

Here it is an example:

<!doctype html>
<meta charset=utf-8>
<title></title>
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id="testDiv" onclick="result1 = remove; result2 = this.remove;"></div>
<script src="MYSCRIPTHERE.js"></script>
<script>
var result1;
var result2;
var unscopables = [
    "before",
    "after",
    "replaceWith",
    "remove",
    "prepend",
    "append"
];
for (var i in unscopables) {
    var name = unscopables[i];
    window[name] = "Hello there";
    result1 = result2 = undefined;
    test(function () {
        assert_true(Element.prototype[Symbol.unscopables][name]);
        var div = document.querySelector('#testDiv');
        div.setAttribute(
            "onclick", "result1 = " + name + "; result2 = this." + name + ";");
        div.dispatchEvent(new Event("click"));
        assert_equals(typeof result1, "string");
        assert_equals(typeof result2, "function");
    }, name + "() should be unscopable");
}
</script>

Thanks! 😄

@abhishekpandey1307
Copy link

Hello,

I’m interested in contributing to this issue and would like to take it up. Could you please assign it to me? I’m eager to work on it and submit a PR soon.

Thank you!

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

2 participants