Skip to content
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

Not compatible with newer versions of playwright #16

Open
PATAPOsha opened this issue May 29, 2023 · 1 comment
Open

Not compatible with newer versions of playwright #16

PATAPOsha opened this issue May 29, 2023 · 1 comment

Comments

@PATAPOsha
Copy link

Everything works fine on playwright==1.27.1
But when updating playwright to 1.31.1 -- all "interception/modifying requests" methods stop working.
like

        def intercept(route: Route, request: Request):
            headers = {
                **request.headers,
                "sec-fetch-site": "same-origin",
                "sec-fetch-mode": "no-cors",
                "sec-fetch-dest": "script",
                ...
            }
            response = self.page.request.fetch(request, headers=headers)
            body = response.text()
           ...

            route.fulfill(
                response=response,
                body=body,
                headers=response.headers,
            )

        self.page.route("*/init.js", intercept)

https://playwright.dev/python/docs/network#modify-requests

@PATAPOsha
Copy link
Author

the reason why my routes didn't work in JS errors.
Seems utils and opts are no longer available in execution context.
image

Execution of all patch-scripts at once in same context fixes the issue. Like joining all scripts into single body and execution it inside single add_init_script()

def stealth_sync(page: SyncPage, config: StealthConfig = None):
    """teaches synchronous playwright Page to be stealthy like a ninja!"""
    scripts = []
    for script in (config or StealthConfig()).enabled_scripts:
        scripts.append(script)
    scripts_payload = "\n".join(scripts)
    page.add_init_script(scripts_payload)

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

1 participant