phantomwright 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. phantomwright-0.0.3/.gitignore +106 -0
  2. phantomwright-0.0.3/LICENSE +21 -0
  3. phantomwright-0.0.3/PKG-INFO +51 -0
  4. phantomwright-0.0.3/README.md +31 -0
  5. phantomwright-0.0.3/phantomwright/__init__.py +5 -0
  6. phantomwright-0.0.3/phantomwright/_impl/__init__.py +0 -0
  7. phantomwright-0.0.3/phantomwright/_impl/_user_sim/_mouse_move_sim.py +36 -0
  8. phantomwright-0.0.3/phantomwright/_impl/_user_sim/_mouse_wheel_sim.py +18 -0
  9. phantomwright-0.0.3/phantomwright/async_api/__init__.py +55 -0
  10. phantomwright-0.0.3/phantomwright/async_api/_patch_evaluate.py +26 -0
  11. phantomwright-0.0.3/phantomwright/async_api/_patch_goto.py +35 -0
  12. phantomwright-0.0.3/phantomwright/stealth/__init__.py +2 -0
  13. phantomwright-0.0.3/phantomwright/stealth/case_insensitive_dict.py +77 -0
  14. phantomwright-0.0.3/phantomwright/stealth/context_managers.py +37 -0
  15. phantomwright-0.0.3/phantomwright/stealth/js/evasions/chrome.app.js +68 -0
  16. phantomwright-0.0.3/phantomwright/stealth/js/evasions/chrome.csi.js +29 -0
  17. phantomwright-0.0.3/phantomwright/stealth/js/evasions/chrome.hairline.js +14 -0
  18. phantomwright-0.0.3/phantomwright/stealth/js/evasions/chrome.load.times.js +116 -0
  19. phantomwright-0.0.3/phantomwright/stealth/js/evasions/chrome.runtime.js +240 -0
  20. phantomwright-0.0.3/phantomwright/stealth/js/evasions/error.prototype.js +3 -0
  21. phantomwright-0.0.3/phantomwright/stealth/js/evasions/iframe.contentWindow.js +95 -0
  22. phantomwright-0.0.3/phantomwright/stealth/js/evasions/media.codecs.js +59 -0
  23. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.hardwareConcurrency.js +7 -0
  24. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.languages.js +9 -0
  25. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.permissions.js +21 -0
  26. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.platform.js +7 -0
  27. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.plugins.js +84 -0
  28. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.userAgent.js +7 -0
  29. phantomwright-0.0.3/phantomwright/stealth/js/evasions/navigator.vendor.js +5 -0
  30. phantomwright-0.0.3/phantomwright/stealth/js/evasions/webgl.vendor.js +26 -0
  31. phantomwright-0.0.3/phantomwright/stealth/js/generate.magic.arrays.js +130 -0
  32. phantomwright-0.0.3/phantomwright/stealth/js/utils.js +435 -0
  33. phantomwright-0.0.3/phantomwright/stealth/stealth.py +524 -0
  34. phantomwright-0.0.3/phantomwright/sync_api/__init__.py +55 -0
  35. phantomwright-0.0.3/phantomwright/sync_api/_patch_evaluate.py +26 -0
  36. phantomwright-0.0.3/phantomwright/sync_api/_patch_goto.py +35 -0
  37. phantomwright-0.0.3/pyproject.toml +46 -0
@@ -0,0 +1,106 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[cod]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ *.egg-info/
24
+ .installed.cfg
25
+ *.egg
26
+ MANIFEST
27
+
28
+ # PyInstaller
29
+ # Usually these files are written by a python script from a template
30
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
31
+ *.manifest
32
+ *.spec
33
+
34
+ # Installer logs
35
+ pip-log.txt
36
+ pip-delete-this-directory.txt
37
+
38
+ # Unit test / coverage reports
39
+ htmlcov/
40
+ .tox/
41
+ .coverage
42
+ .coverage.*
43
+ .cache
44
+ nosetests.xml
45
+ coverage.xml
46
+ *.cover
47
+ .hypothesis/
48
+ .pytest_cache/
49
+
50
+ # Translations
51
+ *.mo
52
+ *.pot
53
+
54
+ # Django stuff:
55
+ *.log
56
+ local_settings.py
57
+ db.sqlite3
58
+
59
+ # Flask stuff:
60
+ instance/
61
+ .webassets-cache
62
+
63
+ # Scrapy stuff:
64
+ .scrapy
65
+
66
+ # Sphinx documentation
67
+ docs/_build/
68
+
69
+ # PyBuilder
70
+ target/
71
+
72
+ # Jupyter Notebook
73
+ .ipynb_checkpoints
74
+
75
+ # pyenv
76
+ .python-version
77
+
78
+ # celery beat schedule file
79
+ celerybeat-schedule
80
+
81
+ # SageMath parsed files
82
+ *.sage.py
83
+
84
+ # Environments
85
+ .env
86
+ .venv
87
+ env/
88
+ venv/
89
+ ENV/
90
+ env.bak/
91
+ venv.bak/
92
+
93
+ # Spyder project settings
94
+ .spyderproject
95
+ .spyproject
96
+
97
+ # Rope project settings
98
+ .ropeproject
99
+
100
+ # mkdocs documentation
101
+ /site
102
+
103
+ # mypy
104
+ .mypy_cache/
105
+
106
+ .idea/
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 ASAS1314
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,51 @@
1
+ Metadata-Version: 2.4
2
+ Name: phantomwright
3
+ Version: 0.0.3
4
+ Summary: Compose patchright + stealth JS + user behavior simulation + more extending
5
+ Project-URL: homepage, https://github.com/ai-microsoft/phantom-wright
6
+ Project-URL: changelog, https://github.com/ai-microsoft/phantom-wright/blob/main/CHANGELOG.md
7
+ Author-email: Hang Yin <hangyin@microsoft.com>, Daniel Wan <benyuwan@microsoft.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Requires-Dist: patchright==1.56.0
14
+ Provides-Extra: black
15
+ Requires-Dist: black>=25.9.0; extra == 'black'
16
+ Provides-Extra: dev
17
+ Requires-Dist: pytest-asyncio>=1.2.0; extra == 'dev'
18
+ Requires-Dist: pytest>=8.4.2; extra == 'dev'
19
+ Description-Content-Type: text/markdown
20
+
21
+ ## Introduction
22
+
23
+ Phantomwright is a library combining [patchright](https://pypi.org/project/patchright/) and [playwright-stealth](https://pypi.org/project/playwright-stealth/), we aim to:
24
+ + Wrap & Re-export API from patchright, provide basic stealth ability
25
+ + Provide the ability to extend playwright, thus you can use API to:
26
+ + Enable stealth injection script
27
+ + Do user simulation
28
+ + (TODO) Setup the ability to add breakpoint into playwright-core and playwright-python
29
+ + (TODO) More extending API support for recaptcha resolver, proxy management etc.
30
+
31
+ ### Initialization & Unit Test
32
+
33
+ ```shell
34
+ uv venv
35
+ .venv\Scripts\activate
36
+ uv sync --extra dev
37
+ uv run patchright install-deps
38
+ uv run patchright install
39
+ uv run pytest
40
+ ```
41
+
42
+ ### Clear VENV Installation
43
+
44
+ ```shell
45
+ uv venv --clear
46
+ ```
47
+
48
+ ### Thanks
49
+
50
+ + [patchright](https://pypi.org/project/patchright/)
51
+ + [playwright-stealth](https://pypi.org/project/playwright-stealth/)
@@ -0,0 +1,31 @@
1
+ ## Introduction
2
+
3
+ Phantomwright is a library combining [patchright](https://pypi.org/project/patchright/) and [playwright-stealth](https://pypi.org/project/playwright-stealth/), we aim to:
4
+ + Wrap & Re-export API from patchright, provide basic stealth ability
5
+ + Provide the ability to extend playwright, thus you can use API to:
6
+ + Enable stealth injection script
7
+ + Do user simulation
8
+ + (TODO) Setup the ability to add breakpoint into playwright-core and playwright-python
9
+ + (TODO) More extending API support for recaptcha resolver, proxy management etc.
10
+
11
+ ### Initialization & Unit Test
12
+
13
+ ```shell
14
+ uv venv
15
+ .venv\Scripts\activate
16
+ uv sync --extra dev
17
+ uv run patchright install-deps
18
+ uv run patchright install
19
+ uv run pytest
20
+ ```
21
+
22
+ ### Clear VENV Installation
23
+
24
+ ```shell
25
+ uv venv --clear
26
+ ```
27
+
28
+ ### Thanks
29
+
30
+ + [patchright](https://pypi.org/project/patchright/)
31
+ + [playwright-stealth](https://pypi.org/project/playwright-stealth/)
@@ -0,0 +1,5 @@
1
+ """
2
+ Patchright + Stealth Plugin + User Behavior Simulation = PhantomWright
3
+ """
4
+
5
+ __version__ = "0.0.3"
File without changes
@@ -0,0 +1,36 @@
1
+ import random
2
+ import logging
3
+ import asyncio
4
+
5
+ logger = logging.getLogger(__name__)
6
+
7
+ async def async_mouse_move(page):
8
+ try:
9
+ await asyncio.sleep(random.uniform(0.5, 1.5))
10
+ viewport = page.viewport_size
11
+ if not viewport:
12
+ return
13
+ width, height = viewport['width'], viewport['height']
14
+ for _ in range(random.randint(3, 7)):
15
+ x = random.randint(100, width - 100)
16
+ y = random.randint(100, height - 100)
17
+ await page.mouse.move(x, y)
18
+ await asyncio.sleep(random.uniform(0.1, 0.3))
19
+ except Exception as e:
20
+ logger.error(f"Error simulating user activity: {e}")
21
+
22
+ def sync_mouse_move(page):
23
+ try:
24
+ import time
25
+ time.sleep(random.uniform(0.5, 1.5))
26
+ viewport = page.viewport_size
27
+ if not viewport:
28
+ return
29
+ width, height = viewport['width'], viewport['height']
30
+ for _ in range(random.randint(3, 7)):
31
+ x = random.randint(100, width - 100)
32
+ y = random.randint(100, height - 100)
33
+ page.mouse.move(x, y)
34
+ time.sleep(random.uniform(0.1, 0.3))
35
+ except Exception as e:
36
+ logger.error(f"Error simulating user activity: {e}")
@@ -0,0 +1,18 @@
1
+ import random
2
+ import logging
3
+
4
+ logger = logging.getLogger(__name__)
5
+
6
+ async def async_mouse_wheel(page):
7
+ try:
8
+ scroll_amount = random.randint(100, 300)
9
+ await page.mouse.wheel(0, scroll_amount)
10
+ except Exception as e:
11
+ logger.error(f"Error simulating mouse wheel activity: {e}")
12
+
13
+ def sync_mouse_wheel(page):
14
+ try:
15
+ scroll_amount = random.randint(100, 300)
16
+ page.mouse.wheel(0, scroll_amount)
17
+ except Exception as e:
18
+ logger.error(f"Error simulating mouse wheel activity: {e}")
@@ -0,0 +1,55 @@
1
+ from patchright.async_api import expect, async_playwright, Accessibility, APIRequest, APIRequestContext, APIResponse, Browser, BrowserContext, BrowserType, CDPSession, ChromiumBrowserContext, ConsoleMessage, Cookie, Dialog, Download, ElementHandle, Error, FileChooser, FilePayload, FloatRect, Frame, FrameLocator, Geolocation, HttpCredentials, JSHandle, Keyboard, Locator, Mouse, Page, PdfMargins, Position, Playwright, ProxySettings, Request, ResourceTiming, Response, Route, Selectors, SourceLocation, StorageState, StorageStateCookie, TimeoutError, Touchscreen, Video, ViewportSize, WebError, WebSocket, WebSocketRoute, Worker
2
+ from ._patch_goto import *
3
+ from ._patch_evaluate import *
4
+
5
+ __all__ = [
6
+ "expect",
7
+ "async_playwright",
8
+ "Accessibility",
9
+ "APIRequest",
10
+ "APIRequestContext",
11
+ "APIResponse",
12
+ "Browser",
13
+ "BrowserContext",
14
+ "BrowserType",
15
+ "CDPSession",
16
+ "ChromiumBrowserContext",
17
+ "ConsoleMessage",
18
+ "Cookie",
19
+ "Dialog",
20
+ "Download",
21
+ "ElementHandle",
22
+ "Error",
23
+ "FileChooser",
24
+ "FilePayload",
25
+ "FloatRect",
26
+ "Frame",
27
+ "FrameLocator",
28
+ "Geolocation",
29
+ "HttpCredentials",
30
+ "JSHandle",
31
+ "Keyboard",
32
+ "Locator",
33
+ "Mouse",
34
+ "Page",
35
+ "PdfMargins",
36
+ "Position",
37
+ "Playwright",
38
+ "ProxySettings",
39
+ "Request",
40
+ "ResourceTiming",
41
+ "Response",
42
+ "Route",
43
+ "Selectors",
44
+ "SourceLocation",
45
+ "StorageState",
46
+ "StorageStateCookie",
47
+ "TimeoutError",
48
+ "Touchscreen",
49
+ "Video",
50
+ "ViewportSize",
51
+ "WebError",
52
+ "WebSocket",
53
+ "WebSocketRoute",
54
+ "Worker",
55
+ ]
@@ -0,0 +1,26 @@
1
+ from functools import wraps
2
+ from patchright.async_api import Page
3
+
4
+ _original_evaluate = Page.evaluate
5
+
6
+
7
+ @wraps(_original_evaluate)
8
+ async def _hooked_evaluate(self, *args, **kwargs):
9
+ # Ensure isolated_context defaults to False if not provided
10
+ kwargs.setdefault("isolated_context", False)
11
+ return await _original_evaluate(self, *args, **kwargs)
12
+
13
+
14
+ Page.evaluate = _hooked_evaluate
15
+
16
+ _original_evaluate_handle = Page.evaluate_handle
17
+
18
+
19
+ @wraps(_original_evaluate_handle)
20
+ async def _hooked_evaluate_handle(self, *args, **kwargs):
21
+ # Ensure isolated_context defaults to False if not provided
22
+ kwargs.setdefault("isolated_context", False)
23
+ return await _original_evaluate_handle(self, *args, **kwargs)
24
+
25
+
26
+ Page.evaluate_handle = _hooked_evaluate_handle
@@ -0,0 +1,35 @@
1
+ import asyncio
2
+ from functools import wraps
3
+ import logging
4
+ import random
5
+ from patchright.async_api import Page
6
+ from phantomwright._impl._user_sim._mouse_move_sim import async_mouse_move
7
+ from phantomwright._impl._user_sim._mouse_wheel_sim import async_mouse_wheel
8
+
9
+ logger = logging.getLogger(__name__)
10
+
11
+
12
+ async def _user_sim_hook(self, *args, **kwargs):
13
+ url = kwargs.get("url")
14
+ if url is None and args:
15
+ url = args[0]
16
+ logger.info(f"Navigating to {url} (async)")
17
+ await async_mouse_move(self)
18
+ await asyncio.sleep(random.uniform(0.1, 0.3))
19
+ await async_mouse_wheel(self)
20
+
21
+
22
+ if not hasattr(Page.goto, "_pre_hooks"):
23
+ _original_goto = Page.goto
24
+
25
+ @wraps(_original_goto)
26
+ async def _hooked_goto(self, *args, **kwargs):
27
+ for hook in _hooked_goto._pre_hooks:
28
+ await hook(self, *args, **kwargs)
29
+ return await _original_goto(self, *args, **kwargs)
30
+
31
+ _hooked_goto._pre_hooks = []
32
+ Page.goto = _hooked_goto
33
+
34
+ if _user_sim_hook not in Page.goto._pre_hooks:
35
+ Page.goto._pre_hooks.append(_user_sim_hook)
@@ -0,0 +1,2 @@
1
+ # -*- coding: utf-8 -*-
2
+ from .stealth import Stealth, ALL_EVASIONS_DISABLED_KWARGS
@@ -0,0 +1,77 @@
1
+ from collections.abc import MutableMapping
2
+
3
+
4
+ # straight from: https://github.com/kennethreitz/requests/blob/master/src/requests/structures.py
5
+ class CaseInsensitiveDict(MutableMapping):
6
+ """A case-insensitive ``dict``-like object.
7
+
8
+ Implements all methods and operations of
9
+ ``MutableMapping`` as well as dict's ``copy``. Also
10
+ provides ``lower_items``.
11
+
12
+ All keys are expected to be strings. The structure remembers the
13
+ case of the last key to be set, and ``iter(instance)``,
14
+ ``keys()``, ``items()``, ``iterkeys()``, and ``iteritems()``
15
+ will contain case-sensitive keys. However, querying and contains
16
+ testing is case insensitive::
17
+
18
+ cid = CaseInsensitiveDict()
19
+ cid['Accept'] = 'application/json'
20
+ cid['aCCEPT'] == 'application/json' # True
21
+ list(cid) == ['Accept'] # True
22
+
23
+ For example, ``headers['content-encoding']`` will return the
24
+ value of a ``'Content-Encoding'`` response header, regardless
25
+ of how the header name was originally stored.
26
+
27
+ If the constructor, ``.update``, or equality comparison
28
+ operations are given keys that have equal ``.lower()``s, the
29
+ behavior is undefined.
30
+ """
31
+
32
+ def __init__(self, data=None, **kwargs):
33
+ self._store = {}
34
+ if data is None:
35
+ data = {}
36
+ self.update(data, **kwargs)
37
+
38
+ def __setitem__(self, key, value):
39
+ # Use the lowercased key for lookups, but store the actual
40
+ # key alongside the value.
41
+ self._store[key.lower()] = (key, value)
42
+
43
+ def __getitem__(self, key):
44
+ return self._store[key.lower()][1]
45
+
46
+ def __delitem__(self, key):
47
+ del self._store[key.lower()]
48
+
49
+ def __iter__(self):
50
+ return (casedkey for casedkey, mappedvalue in self._store.values())
51
+
52
+ def __len__(self):
53
+ return len(self._store)
54
+
55
+ def lower_items(self):
56
+ """Like iteritems(), but with all lowercase keys."""
57
+ return ((lowerkey, keyval[1]) for (lowerkey, keyval) in self._store.items())
58
+
59
+ def __eq__(self, other):
60
+ from collections.abc import Mapping
61
+
62
+ if isinstance(other, Mapping):
63
+ other = CaseInsensitiveDict(other)
64
+ else:
65
+ return NotImplemented
66
+ # Compare insensitively
67
+ return dict(self.lower_items()) == dict(other.lower_items())
68
+
69
+ # Copy is required
70
+ def copy(self):
71
+ return CaseInsensitiveDict(self._store.values())
72
+
73
+ def __repr__(self):
74
+ return str(dict(self.items()))
75
+
76
+ def items(self):
77
+ pass
@@ -0,0 +1,37 @@
1
+ from patchright import async_api, sync_api
2
+
3
+
4
+ class AsyncWrappingContextManager:
5
+ def __init__(self, stealth: "Stealth", manager: async_api.PlaywrightContextManager):
6
+ if isinstance(manager, sync_api.PlaywrightContextManager):
7
+ raise TypeError("You need to call 'use_sync' instead of 'use_async' for a sync Playwright context")
8
+ self.stealth = stealth
9
+ self.manager = manager
10
+
11
+ async def __aenter__(
12
+ self,
13
+ ) -> async_api.Playwright:
14
+ context = await self.manager.__aenter__()
15
+ self.stealth.hook_playwright_context(context)
16
+ return context
17
+
18
+ async def __aexit__(self, exc_type, exc_val, exc_tb) -> None:
19
+ await self.manager.__aexit__(exc_type, exc_val, exc_tb)
20
+
21
+
22
+ class SyncWrappingContextManager:
23
+ def __init__(self, stealth: "Stealth", manager: sync_api.PlaywrightContextManager):
24
+ if isinstance(manager, async_api.PlaywrightContextManager):
25
+ raise TypeError("You need to call 'use_async' instead of 'use_sync' for an async Playwright context")
26
+ self.stealth = stealth
27
+ self.manager = manager
28
+
29
+ def __enter__(
30
+ self,
31
+ ) -> sync_api.Playwright:
32
+ context = self.manager.__enter__()
33
+ self.stealth.hook_playwright_context(context)
34
+ return context
35
+
36
+ def __exit__(self, exc_type, exc_val, exc_tb) -> None:
37
+ self.manager.__exit__(exc_type, exc_val, exc_tb)
@@ -0,0 +1,68 @@
1
+ log("loading chrome.app.js");
2
+
3
+ if (!window.chrome) {
4
+ // Use the exact property descriptor found in headful Chrome
5
+ // fetch it via `Object.getOwnPropertyDescriptor(window, 'chrome')`
6
+ Object.defineProperty(window, "chrome", {
7
+ writable: true,
8
+ enumerable: true,
9
+ configurable: false, // note!
10
+ value: {} // We'll extend that later
11
+ });
12
+ }
13
+
14
+ // app in window.chrome means we're running headful and don't need to mock anything
15
+ if (!("app" in window.chrome)) {
16
+ const makeError = {
17
+ ErrorInInvocation: (fn) => {
18
+ const err = new TypeError(`Error in invocation of app.${fn}()`);
19
+ return utils.stripErrorWithAnchor(err, `at ${fn} (eval at <anonymous>`);
20
+ }
21
+ };
22
+
23
+ const APP_STATIC_DATA = JSON.parse(
24
+ `
25
+ {
26
+ "isInstalled": false,
27
+ "InstallState": {
28
+ "DISABLED": "disabled",
29
+ "INSTALLED": "installed",
30
+ "NOT_INSTALLED": "not_installed"
31
+ },
32
+ "RunningState": {
33
+ "CANNOT_RUN": "cannot_run",
34
+ "READY_TO_RUN": "ready_to_run",
35
+ "RUNNING": "running"
36
+ }
37
+ }
38
+ `.trim()
39
+ );
40
+
41
+ window.chrome.app = {
42
+ ...APP_STATIC_DATA,
43
+
44
+ get isInstalled() {
45
+ return false;
46
+ },
47
+
48
+ getDetails: function getDetails() {
49
+ if (arguments.length) {
50
+ throw makeError.ErrorInInvocation(`getDetails`);
51
+ }
52
+ return null;
53
+ },
54
+ getIsInstalled: function getDetails() {
55
+ if (arguments.length) {
56
+ throw makeError.ErrorInInvocation(`getIsInstalled`);
57
+ }
58
+ return false;
59
+ },
60
+ runningState: function getDetails() {
61
+ if (arguments.length) {
62
+ throw makeError.ErrorInInvocation(`runningState`);
63
+ }
64
+ return "cannot_run";
65
+ }
66
+ };
67
+ utils.patchToStringNested(window.chrome.app);
68
+ }
@@ -0,0 +1,29 @@
1
+ log("loading chrome.csi.js");
2
+
3
+ if (!window.chrome) {
4
+ // Use the exact property descriptor found in headful Chrome
5
+ // fetch it via `Object.getOwnPropertyDescriptor(window, 'chrome')`
6
+ Object.defineProperty(window, "chrome", {
7
+ writable: true,
8
+ enumerable: true,
9
+ configurable: false, // note!
10
+ value: {} // We'll extend that later
11
+ });
12
+ }
13
+
14
+ // Check if we're running headful and don't need to mock anything
15
+ // Check that the Navigation Timing API v1 is available, we need that
16
+ if (!("csi" in window.chrome) && window.performance?.timing) {
17
+ const { csi_timing } = window.performance;
18
+
19
+ log("loading chrome.csi.js");
20
+ window.chrome.csi = function() {
21
+ return {
22
+ onloadT: csi_timing?.domContentLoadedEventEnd,
23
+ startE: csi_timing?.navigationStart,
24
+ pageT: Date.now() - csi_timing?.navigationStart,
25
+ tran: 15 // transition? seems constant
26
+ };
27
+ };
28
+ utils.patchToString(window.chrome.csi);
29
+ }
@@ -0,0 +1,14 @@
1
+ log("loading chrome.hairline.js");
2
+ // inspired by: https://intoli.com/blog/making-chrome-headless-undetectable/
3
+ const elementDescriptor = Object.getOwnPropertyDescriptor(HTMLElement.prototype,
4
+ "offsetHeight");
5
+
6
+ utils.replaceProperty(HTMLDivElement.prototype, "offsetHeight", {
7
+ get: function() {
8
+ // hmmm not sure about this
9
+ if (this.id === "modernizr") {
10
+ return 1;
11
+ }
12
+ return elementDescriptor.get.apply(this);
13
+ }
14
+ });