From 4905ac083b5f570988446a2b9dde3a8747020f1a Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Thu, 11 Jul 2019 10:59:05 +0200 Subject: Cookie injection support MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- crocoite/devtools.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'crocoite/devtools.py') 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 + -- cgit v1.2.3