Skip to content

Commit

Permalink
Fix detection due to cdc_props removal. ultrafunkamsterdam#986
Browse files Browse the repository at this point in the history
  • Loading branch information
lukect committed Jan 14, 2023
1 parent dad751d commit 59422c7
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 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,25 @@ 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

0 comments on commit 59422c7

Please sign in to comment.