summaryrefslogtreecommitdiff
path: root/crocoite/controller.py
diff options
context:
space:
mode:
authorLars-Dominik Braun <lars@6xq.net>2019-07-11 10:59:05 +0200
committerLars-Dominik Braun <lars@6xq.net>2019-07-13 10:32:56 +0200
commit4905ac083b5f570988446a2b9dde3a8747020f1a (patch)
treec9866b6831835526e5dbee038cf48df3de628a82 /crocoite/controller.py
parent8761275f1f569b747cb26578e1c3411e108fb8dd (diff)
downloadcrocoite-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/controller.py')
-rw-r--r--crocoite/controller.py16
1 files changed, 8 insertions, 8 deletions
diff --git a/crocoite/controller.py b/crocoite/controller.py
index 2a848e8..4c9c4b3 100644
--- a/crocoite/controller.py
+++ b/crocoite/controller.py
@@ -33,21 +33,19 @@ from . import behavior as cbehavior
from .browser import SiteLoader, RequestResponsePair, PageIdle, FrameNavigated
from .util import getFormattedViewportMetrics, getSoftwareInfo
from .behavior import ExtractLinksEvent
+from .devtools import toCookieParam
class ControllerSettings:
- __slots__ = ('idleTimeout', 'timeout', 'insecure')
+ __slots__ = ('idleTimeout', 'timeout', 'insecure', 'cookies')
- def __init__ (self, idleTimeout=2, timeout=10, insecure=False):
+ def __init__ (self, idleTimeout=2, timeout=10, insecure=False, cookies=None):
self.idleTimeout = idleTimeout
self.timeout = timeout
self.insecure = insecure
+ self.cookies = cookies or []
- def toDict (self):
- return dict (
- idleTimeout=self.idleTimeout,
- timeout=self.timeout,
- insecure=self.insecure,
- )
+ def __repr__ (self):
+ return f'<ControllerSetting idleTimeout={self.idleTimeout!r}, timeout={self.timeout!r}, insecure={self.insecure!r}, cookies={self.cookies!r}>'
defaultSettings = ControllerSettings ()
@@ -212,6 +210,7 @@ class SinglePageController:
# configure browser
tab = l.tab
await tab.Security.setIgnoreCertificateErrors (ignore=self.settings.insecure)
+ await tab.Network.setCookies (cookies=list (map (toCookieParam, self.settings.cookies)))
# not all behavior scripts are allowed for every URL, filter them
self._enabledBehavior = list (filter (lambda x: self.url in x,
@@ -232,6 +231,7 @@ class SinglePageController:
'timeout': self.settings.timeout,
'behavior': list (map (attrgetter('name'), self._enabledBehavior)),
'insecure': self.settings.insecure,
+ 'cookies': list (map (lambda x: x.OutputString(), self.settings.cookies)),
},
}
if self.warcinfo: