Skip to content

Commit

Permalink
file rename, property rename
Browse files Browse the repository at this point in the history
  • Loading branch information
AtuboDad committed Dec 23, 2020
1 parent 2e94381 commit 1e10870
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ if (
window.PerformancePaintTiming
) {

log.info('loading chrome.loadtimes.js')
const {performance} = window

// Some stuff is not available on about:blank as it requires a navigation to occur,
Expand Down
6 changes: 2 additions & 4 deletions playwright_stealth/js/generate.magic.arrays.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ function generateMagicArray(
magicArray
)

// We need to overlay our custom object with a JS Proxy
const magicArrayObjProxy = new Proxy(magicArrayObj, {
// Override custom object with proxy
return new Proxy(magicArrayObj, {
get(target, key = '') {
// Redirect function calls to our custom proxied versions mocking the vanilla behavior
if (key === 'item') {
Expand Down Expand Up @@ -139,6 +139,4 @@ function generateMagicArray(
return keys
}
})

return magicArrayObjProxy
}
28 changes: 14 additions & 14 deletions playwright_stealth/stealth.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@


def from_file(name):
"""read script from /js data directory"""
"""Read script from ./js directory"""
return pkg_resources.resource_string('playwright_stealth', f'js/{name}').decode()


SCRIPTS: Dict[str, str] = {
'chrome_csi': from_file('chrome.csi.js'),
'chrome_app': from_file('chrome.app.js'),
'chrome_runtime': from_file('chrome.runtime.js'),
'chrome_loadtimes': from_file('chrome.loadtimes.js'),
'chrome_load_times': from_file('chrome.load.times.js'),
'chrome_hairline': from_file('chrome.hairline.js'),
'generate_magic_arrays': from_file('generate.magic.arrays.js'),
'iframe_content_window': from_file('iframe.contentWindow.js'),
Expand All @@ -31,17 +31,17 @@ def from_file(name):
'navigator_hardware_concurrency': from_file('navigator.hardwareConcurrency.js'),
'outerdimensions': from_file('window.outerdimensions.js'),
'utils': from_file('utils.js'),
'webdrive': 'delete Object.getPrototypeOf(navigator).webdriver',
'webdriver': 'delete Object.getPrototypeOf(navigator).webdriver',
'webgl_vendor': from_file('webgl.vendor.js'),
}


@dataclass
class StealthConfig:
"""
Playwright Stealth Configuration that applies stealth strategies to Playwright Page objects.
The stealth strategies are contained in /js package and are basic javascript scripts that are executed
on every Page.goto call.
Playwright stealth configuration that applies stealth strategies to playwright page objects.
The stealth strategies are contained in ./js package and are basic javascript scripts that are executed
on every page.goto() called.
Note:
All init scripts are combined by playwright into one script and then executed this means
the scripts should not have conflicting constants/variables etc. !
Expand All @@ -54,8 +54,8 @@ def enabled_scripts():
yield 'console.log("last script")'
```
"""
# scripts
webdrive: bool = True
# load script options
webdriver: bool = True
webgl_vendor: bool = True
navigator_vendor: bool = True
navigator_plugins: bool = True
Expand All @@ -67,7 +67,7 @@ def enabled_scripts():
media_codecs: bool = True
iframe_content_window: bool = True
chrome_runtime: bool = True
chrome_loadtimes: bool = True
chrome_load_times: bool = True
chrome_csi: bool = True
chrome_app: bool = True
outerdimensions: bool = True
Expand Down Expand Up @@ -103,8 +103,8 @@ def enabled_scripts(self):
yield SCRIPTS['chrome_app']
if self.chrome_runtime:
yield SCRIPTS['chrome_runtime']
if self.chrome_loadtimes:
yield SCRIPTS['chrome_loadtimes']
if self.chrome_load_times:
yield SCRIPTS['chrome_load_times']
if self.chrome_csi:
yield SCRIPTS['chrome_csi']
if self.iframe_content_window:
Expand All @@ -119,8 +119,8 @@ def enabled_scripts(self):
yield SCRIPTS['navigator_plugins']
if self.navigator_vendor:
yield SCRIPTS['navigator_vendor']
if self.webdrive:
yield SCRIPTS['webdrive']
if self.webdriver:
yield SCRIPTS['webdriver']
if self.outerdimensions:
yield SCRIPTS['outerdimensions']
if self.webgl_vendor:
Expand All @@ -142,4 +142,4 @@ def stealth_sync(page: SyncPage, config: StealthConfig = None):
async def stealth_async(page: AsyncPage, config: StealthConfig = None):
"""teaches asynchronous playwright Page to be stealthy like a ninja!"""
for script in (config or StealthConfig()).enabled_scripts:
await page.addInitScript(script)
await page.addInitScript(script)

0 comments on commit 1e10870

Please sign in to comment.