Compute iframe base URL based on page origin (#902)

* Compute iframe base URL based on page origin

* Format
This commit is contained in:
Jonatan Kłosko 2022-01-20 11:29:45 +01:00 committed by GitHub
parent 8bbabcbdb4
commit a9f9c68cfa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 4 deletions

View file

@ -42,7 +42,7 @@ export function leaveChannel() {
*
* * `data-ref` - a unique identifier used as messages scope
*
* * `data-assets-base-url` - the URL to resolve all relative paths
* * `data-assets-base-path` - the path to resolve all relative paths
* against in the iframe
*
* * `data-js-path` - a relative path for the initial output-specific
@ -88,10 +88,12 @@ const JSOutput = {
const handleChildMessage = (message) => {
if (message.type === "ready" && !this.state.childReady) {
const assetsBaseUrl =
window.location.origin + this.props.assetsBasePath;
postMessage({
type: "readyReply",
token: this.state.childToken,
baseUrl: this.props.assetsBaseUrl,
baseUrl: assetsBaseUrl,
jsPath: this.props.jsPath,
});
this.state.childReady = true;
@ -261,7 +263,7 @@ const JSOutput = {
function getProps(hook) {
return {
ref: getAttributeOrThrow(hook.el, "data-ref"),
assetsBaseUrl: getAttributeOrThrow(hook.el, "data-assets-base-url"),
assetsBasePath: getAttributeOrThrow(hook.el, "data-assets-base-path"),
jsPath: getAttributeOrThrow(hook.el, "data-js-path"),
sessionToken: getAttributeOrThrow(hook.el, "data-session-token"),
sessionId: getAttributeOrThrow(hook.el, "data-session-id"),

View file

@ -8,7 +8,7 @@ defmodule LivebookWeb.Output.JSComponent do
phx-hook="JSOutput"
phx-update="ignore"
data-ref={@info.ref}
data-assets-base-url={Routes.session_url(@socket, :show_asset, @session_id, @info.assets.hash, [])}
data-assets-base-path={Routes.session_path(@socket, :show_asset, @session_id, @info.assets.hash, [])}
data-js-path={@info.assets.js_path}
data-session-token={session_token(@info.pid)}
data-session-id={@session_id}>