diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2019-07-11 10:59:05 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2019-07-13 10:32:56 +0200 |
commit | 4905ac083b5f570988446a2b9dde3a8747020f1a (patch) | |
tree | c9866b6831835526e5dbee038cf48df3de628a82 /crocoite/devtools.py | |
parent | 8761275f1f569b747cb26578e1c3411e108fb8dd (diff) | |
download | crocoite-4905ac083b5f570988446a2b9dde3a8747020f1a.tar.gz crocoite-4905ac083b5f570988446a2b9dde3a8747020f1a.tar.bz2 crocoite-4905ac083b5f570988446a2b9dde3a8747020f1a.zip |
Cookie injection support
Add command-line options injecting individual cookies or cookie file
into Chrome. Provide default cookie file.
This changes the IRC bot’s command splitting to shlex.split, which
allows shell-like argument quoting.
Fixes #7.
Diffstat (limited to 'crocoite/devtools.py')
-rw-r--r-- | crocoite/devtools.py | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/crocoite/devtools.py b/crocoite/devtools.py index 412ab08..05680f1 100644 --- a/crocoite/devtools.py +++ b/crocoite/devtools.py @@ -25,6 +25,8 @@ Communication with Google Chrome through its DevTools protocol. import json, asyncio, logging, os from tempfile import mkdtemp import shutil +from http.cookies import Morsel + import aiohttp, websockets from yarl import URL @@ -366,3 +368,26 @@ class Passthrough: async def __aexit__ (self, *exc): return False +def toCookieParam (m): + """ + Convert Python’s http.cookies.Morsel to Chrome’s CookieParam, see + https://chromedevtools.github.io/devtools-protocol/1-3/Network#type-CookieParam + """ + + assert isinstance (m, Morsel) + + out = {'name': m.key, 'value': m.value} + + # unsupported by chrome + for k in ('max-age', 'comment', 'version'): + if m[k]: + raise ValueError (f'Unsupported cookie attribute {k} set, cannot convert') + + for mname, cname in [('expires', None), ('path', None), ('domain', None), ('secure', None), ('httponly', 'httpOnly')]: + value = m[mname] + if value: + cname = cname or mname + out[cname] = value + + return out + |