Rayrun
← Back to Discord Forum

Eval on pages that overwrite window.eval?

Is there any way to forcibly allow evaluation even on these pages?

This thread is trying to answer question "Is there any way to forcibly allow evaluation even on these pages that overwrite window.eval?"

0 replies

Answer

Sure, you can force evaluation on pages that overwrite window.eval(). In @playwright/test, you can use page.evaluate() to run JavaScript functions in the page context and get the results back. This lets you access browser globals like window and document.

By default, @playwright/test performs actionability checks before executing actions like clicking or setting values. These checks ensure that the target elements are attached, visible, stable, receive events, and are enabled. But, if you want to bypass these checks and force an action, you can use the force option.

For instance, when using page.click(), passing a truthy value for the force option will disable the check that verifies whether the target element actually receives click events. This can be useful in cases where certain pages overwrite or modify default behavior.

Here's an example of using page.click() with the force option:

await page.click('button', { force: true });

This will perform a click on the specified button element without checking if it receives click events.

Remember, forcing actions should be used with caution as it may lead to unexpected behavior on certain pages. It's recommended to only use this option when necessary and after considering any potential consequences.

So, by using @playwright/test's evaluation methods like page.evaluate() and the force option for specific actions, you can force evaluation even on pages that overwrite or modify window.eval().

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email luc@ray.run.