-
Notifications
You must be signed in to change notification settings - Fork 32
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
Patch for __pwInitScripts
#52
Comments
Same issue in my side as well, can it cause a detection? |
I got it fixed with the following code: await browser.addInitScript(() => {
delete (window as any).__pwInitScripts;
}) |
Works only every second try. Is there any solution that 100% works? |
Solution via a proxy await context.addInitScript(() => {
// Delete the property if it exists
delete (window as any).__pwInitScripts;
// Redefine `Object.getOwnPropertyNames`
const originalGetOwnPropertyNames = Object.getOwnPropertyNames;
Object.getOwnPropertyNames = function (obj) {
const props = originalGetOwnPropertyNames(obj);
return props.filter((prop) => prop !== '__pwInitScripts');
};
// Use a Proxy to handle access to `window`
const windowHandler = {
get(target: any, prop: string) {
if (prop === '__pwInitScripts') {
return undefined; // Hide the property
}
return Reflect.get(target, prop);
},
has(target: any, prop: string) {
if (prop === '__pwInitScripts') {
return false; // Prevent detection via "in" operator
}
return Reflect.has(target, prop);
},
};
const proxiedWindow = new Proxy(window, windowHandler);
Object.defineProperty(globalThis, 'window', {
value: proxiedWindow,
configurable: false,
writable: false,
});
}) |
I'd be careful with using proxies. The presence of a proxy can be detected by client bot detector libraries and a proxy on the window object is probably going to ring some alarm bells. Just FYI. |
Creating this issue so I can track it 😄
Need to fix the
__pwInitScripts
detection introduced in playwright 1.46.1microsoft/playwright@c9e673c#diff-087773eea292da9db5a3f27de8f1a2940cdb895383ad750c3cd8e01772a35b40R909-R924
The text was updated successfully, but these errors were encountered: