I need to change the clock of the Playwright Python browser. I know this can be done in JavaScript, but is there a way to do this with the Python Playwright library? I've tried converting the JavaScript code to Python but it doesn't work.
Asked
Active
Viewed 58 times
1 Answers
1
You can use the evaluate
-method to execute Javascript on the page:
import playwright
def execute_js(page):
page.evaluate(
"""
page.evaluate(() => {
Date.now = () => {
return 1609477200000; //Jan 1, 2021
};
});
"""
)
with playwright.create_browser().new_page() as page:
execute_js(page)
print(page.evaluate("Date.now()"))

Christian Baumann
- 3,188
- 3
- 20
- 37