-
-
Notifications
You must be signed in to change notification settings - Fork 216
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
[With test] Embedded JavaScript is not executed #1692
Comments
Thank you for reporting @Spixmaster! 🙂 I'm not exactly sure why it is not loaded at all. I need to investigate further. But at least one of the reasons is because Happy DOM doesn't have support for ESM scripts (import, export etc.) yet. However, I also need support for ESM for one project and a lot of other people in the community do to, so I will definitely prioritize adding support for it. Task: |
@capricorn86 I further investigated the issue. It related to this one, oven-sh/bun#16363. It seems to be an error by Bun. |
@Spixmaster Happy DOM now supports ECMAScript Modules. This should help with loading the page 🙂 |
The error still persist but as mentioned before is probably caused by oven-sh/bun#16363. |
I tried the following with Nodejs since Bun has the mentioned error. The embedded JavaScript is still not executed. Source code: import {GlobalRegistrator} from "@happy-dom/global-registrator";
import {Browser, type BrowserContext, type BrowserPage} from "happy-dom";
(async (): Promise<undefined> =>
{
{
GlobalRegistrator.register();
const browser: Browser = new Browser({
settings: {
disableErrorCapturing: true,
disableJavaScriptEvaluation: false
}
});
const context: BrowserContext = browser.defaultContext;
const page: BrowserPage = context.newPage();
await page.goto("https://www.arbeitsagentur.de/jobsuche/suche?berufsfeld=Landwirtschaft&angebotsart=1");
//@ts-expect-error
global.window = page.mainFrame.window;
//@ts-expect-error
global.document = page.mainFrame.window.document;
localStorage.clear();
await page.waitUntilComplete();
//TODO
console.log(page.content);
}
{
const browser: Browser = new Browser({
settings: {
disableErrorCapturing: true,
disableJavaScriptEvaluation: false
}
});
const context: BrowserContext = browser.defaultContext;
const page: BrowserPage = context.newPage();
//@ts-expect-error
const document: Document = page.mainFrame.document;
const html_content = `
<!DOCTYPE html>
<html>
<head>
<title>Happy DOM Example</title>
<script id="a">
console.log("hi from page");
const messageElement = document.getElementById('message');
if (messageElement) {
messageElement.textContent = 'Hello from Happy DOM!';
}
</script>
</head>
<body>
<div id="message">Original Content</div>
</body>
</html>
`;
document.write(html_content);
await page.waitUntilComplete();
//Uncommented for a workaround.
//const script = document.getElementById("a");
//assert(script !== null);
//console.log(script.textContent);
//page.evaluate(script.textContent);
//Verify the result.
const messageElement = document.getElementById("message");
console.log(messageElement?.textContent); // Outputs: "Hello from Happy DOM!"
}
})();
|
@canadaduane Do you have expertise to this issue? |
v16.6.0 with Bun.
The following test does not produce the website like in the browser due to no execution of the JavaScript.
Is it even possible to use happy-dom with these websites or do I need to use puppeteer?
I can even reproduce with a much simpler example. JavaScript is not executed automatically.
The text was updated successfully, but these errors were encountered: