mirror of
https://github.com/internetarchive/brozzler.git
synced 2025-08-03 12:06:28 -04:00
Use Network.setBlockedUrls instead of Debugger to block URLs
This commit is contained in:
parent
fc000ff515
commit
f54d62ea40
1 changed files with 9 additions and 27 deletions
|
@ -200,21 +200,6 @@ class WebsockReceiverThread(threading.Thread):
|
||||||
'uncaught exception in _handle_message message=%s',
|
'uncaught exception in _handle_message message=%s',
|
||||||
message, exc_info=True)
|
message, exc_info=True)
|
||||||
|
|
||||||
def _debugger_paused(self, message):
|
|
||||||
# we hit the breakpoint set in start(), get rid of google analytics
|
|
||||||
self.logger.debug('debugger paused! message=%s', message)
|
|
||||||
scriptId = message['params']['callFrames'][0]['location']['scriptId']
|
|
||||||
|
|
||||||
# replace script
|
|
||||||
self.websock.send(
|
|
||||||
json.dumps(dict(
|
|
||||||
id=0, method='Debugger.setScriptSource',
|
|
||||||
params={'scriptId': scriptId,
|
|
||||||
'scriptSource': 'console.log("google analytics is no more!");'})))
|
|
||||||
|
|
||||||
# resume execution
|
|
||||||
self.websock.send(json.dumps(dict(id=0, method='Debugger.resume')))
|
|
||||||
|
|
||||||
def _network_response_received(self, message):
|
def _network_response_received(self, message):
|
||||||
if (message['params']['response']['status'] == 420
|
if (message['params']['response']['status'] == 420
|
||||||
and 'Warcprox-Meta' in CaseInsensitiveDict(
|
and 'Warcprox-Meta' in CaseInsensitiveDict(
|
||||||
|
@ -255,8 +240,6 @@ class WebsockReceiverThread(threading.Thread):
|
||||||
elif message['method'] == 'Network.requestWillBeSent':
|
elif message['method'] == 'Network.requestWillBeSent':
|
||||||
if self.on_request:
|
if self.on_request:
|
||||||
self.on_request(message)
|
self.on_request(message)
|
||||||
elif message['method'] == 'Debugger.paused':
|
|
||||||
self._debugger_paused(message)
|
|
||||||
elif message['method'] == 'Page.interstitialShown':
|
elif message['method'] == 'Page.interstitialShown':
|
||||||
# for AITFIVE-1529: handle http auth
|
# for AITFIVE-1529: handle http auth
|
||||||
# for now, we should consider killing the browser when we receive Page.interstitialShown and
|
# for now, we should consider killing the browser when we receive Page.interstitialShown and
|
||||||
|
@ -332,9 +315,10 @@ class Browser:
|
||||||
msg_id = next(self._command_id)
|
msg_id = next(self._command_id)
|
||||||
kwargs['id'] = msg_id
|
kwargs['id'] = msg_id
|
||||||
msg = json.dumps(kwargs)
|
msg = json.dumps(kwargs)
|
||||||
logging.log(
|
#logging.log(
|
||||||
brozzler.TRACE if suppress_logging else logging.DEBUG,
|
# brozzler.TRACE if suppress_logging else logging.DEBUG,
|
||||||
'sending message to %s: %s', self.websock, msg)
|
# 'sending message to %s: %s', self.websock, msg)
|
||||||
|
# print(msg)
|
||||||
self.websock.send(msg)
|
self.websock.send(msg)
|
||||||
return msg_id
|
return msg_id
|
||||||
|
|
||||||
|
@ -358,16 +342,14 @@ class Browser:
|
||||||
self.send_to_chrome(method='Network.enable')
|
self.send_to_chrome(method='Network.enable')
|
||||||
self.send_to_chrome(method='Page.enable')
|
self.send_to_chrome(method='Page.enable')
|
||||||
self.send_to_chrome(method='Console.enable')
|
self.send_to_chrome(method='Console.enable')
|
||||||
self.send_to_chrome(method='Debugger.enable')
|
|
||||||
self.send_to_chrome(method='Runtime.enable')
|
self.send_to_chrome(method='Runtime.enable')
|
||||||
|
|
||||||
# disable google analytics, see _handle_message() where breakpoint
|
# disable google analytics
|
||||||
# is caught Debugger.paused
|
|
||||||
self.send_to_chrome(
|
self.send_to_chrome(
|
||||||
method='Debugger.setBreakpointByUrl',
|
method='Network.setBlockedURLs',
|
||||||
params={
|
params={'urls': ['http://www.google-analytics.com/analytics.js',
|
||||||
'lineNumber': 1,
|
'https://www.google-analytics.com/analytics.js']
|
||||||
'urlRegex': 'https?://www.google-analytics.com/analytics.js'})
|
)
|
||||||
|
|
||||||
def stop(self):
|
def stop(self):
|
||||||
'''
|
'''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue