-
Notifications
You must be signed in to change notification settings - Fork 3
How the extension works
This page explains how the VTT Bridge extension works.

The extension runs 2 content scripts and 1 background script, which perform the following tasks:
-
dmv.js: Add event listeners to DMV and send commands tobackground.js. -
background.js: Receive commands fromdmv.jsand send commands toroll20.js. -
roll20.js: Receive commands frombackground.jsand run commands on Roll20.
This structure is necessary because of the limits of browser extensions.
Ideally, we would like to send commands directly from DMV to Roll20.
// Ideal case: direct message passing
DMV content script -> Roll20 content script
However, you cannot send messages from one content script to another, so we must use a background script as a relay.
// Workaround: background script relay
DMV content script -> background script -> Roll20 content script
Unfortunately, sending a message from a background script to an arbitrary content script requires the tabs permission. This permission allows the extension to "create, modify, and rearrange tabs in the browser", which is unnecessarily powerful. To sidestep this permission, we implement a polling mechanism.
// Workaround: polling mechanism
DMV content script -> background script <-> Roll20 content script
At regular intervals (e.g. every second), the Roll20 content script will send a request to the background script. The background script will receive this request, then reply with a list of commands. Neither the request nor the reply require additional permissions.
In the future, this polling mechanism could be improved by using the runtime.Port API.