JavaScript Injector

The JavaScript Injector from Screenly introduces an innovative utility to your digital signage content development toolkit. This feature enables the execution of JavaScript code on a website. While the most prominent application is logging into websites, its capabilities extend beyond this. For instance, it can be used to dismiss GDPR consent dialogs, providing a more seamless user experience.

Getting Started

To get started, install the Screenly CLI.

To use the JavaScript Injector, you first need to create the web asset.

You can do that in the user interface, our CLI or by using our API directly. The recommended way to work with our JavaScript Injector is to use the CLI, so we will be using that for the documentation.

Add Engadget as an asset

$ screenly asset add https://www.engadget.com Engadget
+----------------------------+-------------+------+--------+
| Id                        | Title     | Type | Status |
+----------------------------+-------------+------+--------+
| XXXXXXXXXXXXXXXXXXXXXXXXXX | Engadget | N/A  | none   |
+----------------------------+-------------+------+--------+

Let's store the Asset ID for later

$ export ASSET_ID=XXXXXXXXXXXXXXXXXXXXXXXXXX

Alternatively, we can use the nifty --json option in the CLI and pipe it to jq to get just the Asset ID:

$ screenly asset list --json | jq -r '.[] | select (.title|test("Engadget")) | .id'
XXXXXXXXXXXXXXXXXXXXXXXXXX

With our asset created, we can now apply the JavaScript Injection for this site. The above site, Engadget, uses Yahoo's cookie consent popover. When you first navigate to the site, you need to click the cookie consent dialog to continue. This is obviously not ideal for digital signage.

Luckily, we can use JavaScript to close this dialog. The script yahoo-cookies-consent-closing.js does just that, so let's apply it to our asset using the CLI.

Apply our Yahoo cookie consent closer to the Engadget asset

$ export JAVASCRIPT_URL='https://raw.githubusercontent.com/Screenly/playground/master/javascript-injectors/examples/yahoo-cookies-consent-closing.js'
$ screenly asset inject-js "$ASSET_ID" "$JAVASCRIPT_URL"
20XX-XX-XXTXX:XX:XX.XXXZ INFO  [screenly] Asset updated successfully.

That's it! When the asset loads on your screen, the above snippet will run automatically and close the cookie consent dialog.

Important considerations

Examples