Skip to content

Commit

Permalink
added suppress_origin
Browse files Browse the repository at this point in the history
  • Loading branch information
Martino Trevisan authored and Martino Trevisan committed Mar 7, 2024
1 parent 02a6e7f commit b9dc829
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions PyChromeDevTools/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ def __init__(
port=9222,
tab=0,
timeout=TIMEOUT,
auto_connect=True
auto_connect=True,
suppress_origin=False
):
self.host = host
self.port = port
self.ws = None
self.tabs = None
self.timeout = timeout
self.suppress_origin = suppress_origin

if auto_connect:
self.connect(tab=tab)

Expand All @@ -57,7 +60,7 @@ def connect(self, tab=0, update_tabs=True):
self.get_tabs()
wsurl = self.tabs[tab]['webSocketDebuggerUrl']
self.close()
self.ws = websocket.create_connection(wsurl)
self.ws = websocket.create_connection(wsurl, suppress_origin=self.suppress_origin)
self.ws.settimeout(self.timeout)

def connect_targetID(self, targetID):
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ chrome = PyChromeDevTools.ChromeInterface(host="1.1.1.1",port=1234)
```
By default it uses `localhost:9222`.

**Note for Android:** The `ChromeInterface()` constructor accepts the `suppress_origin` argument which defaults to `False`. Set it to `True` to suppress the Origin Header in the created websockets. This is apparently needed in Android environments.

You can connect directly to a `targetID` using the method `connect_targetID`.
You must pass the `targetID` as parameter to this function.
In this case, you avoid querying the json and finding the `tab id`.
Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
name="PyChromeDevTools",
description="PyChromeDevTools : Interact with Google Chrome using the Chrome DevTools Protocol.",
license="Apache License 2.0",
version="0.4",
version="1.0.3",
author="Martino Trevisan",
author_email="[email protected]",
maintainer="Martino Trevisan",
maintainer_email="[email protected]",
url="https://github.com/marty90/PyChromeDevTools",
download_url = 'https://github.com/marty90/PyChromeDevTools/tarball/1.0.2',
download_url = 'https://github.com/marty90/PyChromeDevTools/tarball/1.0.3',
packages=['PyChromeDevTools'],
install_requires=['requests', 'websocket-client']
)
Expand Down

0 comments on commit b9dc829

Please sign in to comment.