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

Fix detection due to cdc_props removal. #986 #993

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 8 additions & 14 deletions undetected_chromedriver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from __future__ import annotations


__version__ = "3.2.1"
__version__ = "3.2.2"

import json
import logging
Expand Down Expand Up @@ -608,29 +608,23 @@ def _get_cdc_props(self):
while(objectToInspect !== null)
{ result = result.concat(Object.getOwnPropertyNames(objectToInspect));
objectToInspect = Object.getPrototypeOf(objectToInspect); }
return result.filter(i => i.match(/.+_.+_(Array|Promise|Symbol)/ig))
return result.filter(i => i.match(/^[a-z]{3}_[a-z]{22}_.*/i))
"""
)

def _hook_remove_cdc_props(self):
def _hook_remove_cdc_props(self, cdc_props):
if len(cdc_props) < 1:
return
cdc_props_js_array = '[' + ', '.join('"' + p + '"' for p in cdc_props) + ']'
self.execute_cdp_cmd(
"Page.addScriptToEvaluateOnNewDocument",
{
"source": """
let objectToInspect = window,
result = [];
while(objectToInspect !== null)
{ result = result.concat(Object.getOwnPropertyNames(objectToInspect));
objectToInspect = Object.getPrototypeOf(objectToInspect); }
result.forEach(p => p.match(/.+_.+_(Array|Promise|Symbol)/ig)
&&delete window[p]&&console.log('removed',p))
"""
"source": cdc_props_js_array + ".forEach(p => delete window[p] && console.log('removed', p));"
},
)

def get(self, url):
if self._get_cdc_props():
self._hook_remove_cdc_props()
self._hook_remove_cdc_props(self._get_cdc_props())
return super().get(url)

def add_cdp_listener(self, event_name, callback):
Expand Down