Page.addScriptTag() not working with path or content

Viewed 339

I have being trying to inject a shared web worker in javascript using puppeteer, so as to remove the need to keep going in and out of Documents (avoiding frequent serialization) scope.but Page.addScriptTag() doesn't seem to work. So far i have tried the following and many more

const shared_worker_path = path.join(__dirname, "js_shared_worker.js");
    await browser.on("targetchanged", async target => {
        let p = await target.page();
        //Tried to wait for body. doesn't help.
        await p.waitForSelector("body");
        //Tried waiting for navigation too does't help
        page.on('console', (msg) => console.log(msg.type().toUpperCase() + ":", msg.text()));
        await p.evaluate(async () => {
            //
            alert("I don't understand why!");
        });        let eh = await p.addScriptTag({
            //this doesn't work
            path:shared_worker_path,
            //This doesn't work too
            //content: (async () => {
            //  alert("Just discovered a new deadend. wanna test?");
            //})()
        });
        //works
        console.log(p.url());
        //Prints: Promise{ <pending> }
        console.log(eh.jsonValue());

    });

if by any chance what i am trying to achieve (implied by the code) is not feasible, then i would appreciate if made aware. I am also aware of existing question which are almost similar, they address matters different than what i want addressed. If in case you tried the code, sorry for the alerts.
js_shared_worker.js

alert( document.querySelector("script[src*=js_shared_worker.js]").getAttribute("src") );

I am grateful in advance for your help.

0 Answers
Related