summaryrefslogtreecommitdiff
path: root/crocoite/devtools.py
diff options
context:
space:
mode:
Diffstat (limited to 'crocoite/devtools.py')
-rw-r--r--crocoite/devtools.py25
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
+