From 5930d764693a0dc21f8a1c2304a694dd88ec2cf6 Mon Sep 17 00:00:00 2001 From: Joey Parrish Date: Sat, 18 May 2024 08:53:01 -0700 Subject: [PATCH] feat(chromecast)!: Add v2 receiver app with a redirect mode (#96) This introduces an optional redirect mode, which changes the top URL instead of using an iframe to host content. This requires the Cast SDK to be loaded at the destination URL. This can be used for Shaka Player testing, but not for every URL you might want to see on a Chromecast. This requires deployment to a new receiver app ID. --- backends/chromecast/README.md | 2 + backends/chromecast/cast-utils.js | 14 ++- backends/chromecast/how-it-works.md | 15 ++- backends/chromecast/receiver-deployment.md | 2 +- backends/chromecast/receiver.html | 120 +++++++++------------ 5 files changed, 79 insertions(+), 74 deletions(-) diff --git a/backends/chromecast/README.md b/backends/chromecast/README.md index e5b758f..5a695c8 100644 --- a/backends/chromecast/README.md +++ b/backends/chromecast/README.md @@ -40,6 +40,8 @@ This backend supports the following parameters: - `receiver-app-id`: The receiver app ID to load, in case you want to host your own copy. (See also [receiver-deployment.md](https://github.com/shaka-project/generic-webdriver-server/blob/main/backends/chromecast/receiver-deployment.md)) + - `redirect`: Use a redirect strategy instead of an iframe; requires the Cast + SDK to be loaded at the destination URL. Use this for Shaka Player testing. - `idle-timeout-seconds`: The timeout for idle sessions, after which they will be closed. - `connection-timeout-seconds`: The connection timeout for the Chromecast, diff --git a/backends/chromecast/cast-utils.js b/backends/chromecast/cast-utils.js index b2bbf4e..a41cb36 100644 --- a/backends/chromecast/cast-utils.js +++ b/backends/chromecast/cast-utils.js @@ -91,7 +91,10 @@ function cast(flags, log, mode, url) { request.appId = flags.receiverAppId; // This is substituted in place of ${POST_DATA} in the registered // receiver URL. - request.commandParameters = url; + request.commandParameters = JSON.stringify({ + url, + redirect: flags.redirect, + }); break; case Mode.SERIAL_NUMBER: @@ -181,7 +184,14 @@ function addChromecastArgs(yargs) { .option('receiver-app-id', { description: 'The Chromecast receiver app ID', type: 'string', - default: 'B602D163', + default: '29993EC8', + }) + .option('redirect', { + description: + 'Use a redirect strategy instead of an iframe;' + + ' requires the Cast SDK to be loaded at the destination URL', + type: 'boolean', + default: false, }) .option('connection-timeout-seconds', { description: 'A timeout for the Chromecast connection', diff --git a/backends/chromecast/how-it-works.md b/backends/chromecast/how-it-works.md index e02fa62..17dff54 100644 --- a/backends/chromecast/how-it-works.md +++ b/backends/chromecast/how-it-works.md @@ -16,7 +16,9 @@ Receiver apps are really just web pages, and everything on the screen is implemented in HTML, CSS, and JavaScript. The Chromecast WebDriver server's receiver app hosts an iframe which can be -redirected to any URL at the client's request. This is how we load the +redirected to any URL at the client's request. If the URL is known to load +the Cast SDK, then the receiver app can also redirect to that URL instead, +providing a frameless environment. These are our two methods of loading an arbitrary URL requested by a test runner like [Karma][] without changing the receiver app's registered URL. @@ -49,14 +51,19 @@ Source: https://developer.mozilla.org/en-US/docs/Web/HTTP/Feature_Policy ## Access Limitations -We show an arbitrary URL on the device by embedding it into an iframe in our -Chromecast receiver app. However, sites can prevent iframe-embedding with the -[`X-Frame-Options` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options). +We can show an arbitrary URL on the device by embedding it into an iframe in +our Chromecast receiver app. However, sites can prevent iframe-embedding with +the [`X-Frame-Options` header](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-Options). Though this should not be an issue for a test runner, this may affect other URLs. Unfortunately, there is no way for the receiver app to detect when this has happened. See: https://github.com/shaka-project/generic-webdriver-server/issues/8 +When possible, such as in Chromecast testing, you should use the `--redirect` +flag and load the Cast SDK in your test environment. This allows you to avoid +the iframe and its limitations, and provides your tests with a flat environment +more representative of your app's production environment. + ## Chromecast receiver deployment diff --git a/backends/chromecast/receiver-deployment.md b/backends/chromecast/receiver-deployment.md index 7d45184..7d818f2 100644 --- a/backends/chromecast/receiver-deployment.md +++ b/backends/chromecast/receiver-deployment.md @@ -82,7 +82,7 @@ property: ```sh java \ - -Dgenericwebdriver.backend.params.receiver-app-id=B602D163 \ + -Dgenericwebdriver.backend.params.receiver-app-id=29993EC8 \ # ... ``` diff --git a/backends/chromecast/receiver.html b/backends/chromecast/receiver.html index 26b4320..ac370bf 100644 --- a/backends/chromecast/receiver.html +++ b/backends/chromecast/receiver.html @@ -17,8 +17,7 @@ - Chromecast WebDriver Receiver - + Chromecast WebDriver Receiver v2 - - - +