Skip to content

Commit

Permalink
Added support for headers
Browse files Browse the repository at this point in the history
  • Loading branch information
choeflake committed Oct 29, 2021
1 parent 3eb2731 commit cce04a4
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 11 deletions.
26 changes: 18 additions & 8 deletions .sv/control/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def update(self, page):
if not self._socket_url:
# Might be empty in /json/list
self._socket_url = page['webSocketDebuggerUrl']
# For rpc information, see https://chromedevtools.github.io/devtools-protocol/
self.ensure_connected()

def ensure_connected(self):
Expand All @@ -93,6 +94,7 @@ def ensure_connected(self):
return
log("websocket connected")
self._eventloop.register(self._fd, self.receive_rpc)
self.call_rpc("Network.enable")
self.call_rpc("Page.enable")
self.call_rpc("Runtime.enable")
self.call_rpc("DOM.enable")
Expand Down Expand Up @@ -190,10 +192,12 @@ def receive_rpc(self):
traceback.print_exc()
self.reset_connection()

def navigate(self, url, scripts):
def navigate(self, url, scripts, headers):
self._loaded = False
self._frames = {}
self._scripts = scripts
self._headers = headers
self.call_rpc("Network.setExtraHTTPHeaders", headers=headers)
self.call_rpc("Page.navigate", url=url)

class Browser(object):
Expand Down Expand Up @@ -229,10 +233,10 @@ def open(self, url):
self._tab_by_id[id]= Tab(self._eventloop, page)
self._tabs.append(id)

def navigate(self, idx, url, script):
def navigate(self, idx, url, script, headers):
id = self.tabs[idx]
log("=== Navigate %s -> %s" % (id, url))
self._tab_by_id[id].navigate(url, script)
log("=== Navigate %s -> %s (headers: %s)" % (id, url, headers))
self._tab_by_id[id].navigate(url, script, headers)

def switch_to(self, idx):
id = self.tabs[idx]
Expand Down Expand Up @@ -319,10 +323,16 @@ def load_config(self):
with open(os.path.join(self._prefix, config['scripts']['asset_name'])) as s:
scripts = Scripts(json.load(s))

headers = {}
_headers = config['headers']
if _headers:
for item in _headers:
headers[item['name']] = item['value']

urls = config['urls']
if urls:
self._urls = cycle([
(item['duration'], item['url'], scripts)
(item['duration'], item['url'], scripts, headers)
for item in urls
if item['duration'] > 0
]).next
Expand Down Expand Up @@ -378,11 +388,11 @@ def ensure_two_tabs(self):
return fixed

def preload_next(self):
self._next_duration, url, scripts = self._config.next_item()
self._next_duration, url, scripts, headers = self._config.next_item()
log("[browser-control] Loading %s in tab 1: next switch %d (in %ds)" % (
url, self._next_switch, self._next_switch - time.time()
))
self._browser.navigate(1, url, scripts)
self._browser.navigate(1, url, scripts, headers)
self._preloading = True

def tick(self):
Expand Down Expand Up @@ -417,7 +427,7 @@ def tick(self):
send_ib('root/fade:1')
self._next_switch = now + self._next_duration
self._preloading = False
self._browser.navigate(1, 'about:blank', Scripts([]))
self._browser.navigate(1, 'about:blank', Scripts([]), {})

config_json = os.path.join(os.environ['NODE_PATH'], 'config.json')
if len(sys.argv) == 2:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@ thanks for the great work!
This version is mentioned to support HTTP request headers. For example
the `Authorization` header.

[![Import](https://cdn.infobeamer.com/s/img/import.png)](https://info-beamer.com/use?url=https://github.com/choeflake/infobeamer-fullscreen-browser-package.git)

# Git LFS

This repository uses Git LFS for the large filesystem overlay. See https://docs.github.com/en/repositories/working-with-files/managing-large-files/configuring-git-large-file-storage.

# Experimental browser for info-beamer hosted

This package allows you to show webpages in a constant rotation.
Expand Down
18 changes: 18 additions & 0 deletions node.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,24 @@
{
"title": "Advanced settings",
"type": "section"
}, {
"title": "Which headers do you want to add?",
"name": "headers",
"type": "list",
"itemname": "Header",
"items": [{
"title": "Header",
"ui_width": 3,
"name": "name",
"type": "string",
"default": ""
}, {
"title": "Value",
"ui_width": 9,
"name": "value",
"type": "string",
"default": ""
}]
}, {
"title": "Time Zone",
"ui_width": 6,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "Fullscreen Browser",
"name": "Fullscreen Browser+",
"author": "info-beamer.com",
"version": "86",
"desc": "Chromium Browser packaged as an info-beamer hosted 'service'",
"version": "86.plus",
"desc": "Chromium Browser packaged as an info-beamer hosted 'service'. With support for custom request headers.",
"runtime": {
"transparent": true
},
Expand Down

0 comments on commit cce04a4

Please sign in to comment.