mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-09 21:16:26 +08:00
Compute iframe base URL based on page origin (#902)
* Compute iframe base URL based on page origin * Format
This commit is contained in:
parent
8bbabcbdb4
commit
a9f9c68cfa
2 changed files with 6 additions and 4 deletions
|
@ -42,7 +42,7 @@ export function leaveChannel() {
|
||||||
*
|
*
|
||||||
* * `data-ref` - a unique identifier used as messages scope
|
* * `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
|
* against in the iframe
|
||||||
*
|
*
|
||||||
* * `data-js-path` - a relative path for the initial output-specific
|
* * `data-js-path` - a relative path for the initial output-specific
|
||||||
|
@ -88,10 +88,12 @@ const JSOutput = {
|
||||||
|
|
||||||
const handleChildMessage = (message) => {
|
const handleChildMessage = (message) => {
|
||||||
if (message.type === "ready" && !this.state.childReady) {
|
if (message.type === "ready" && !this.state.childReady) {
|
||||||
|
const assetsBaseUrl =
|
||||||
|
window.location.origin + this.props.assetsBasePath;
|
||||||
postMessage({
|
postMessage({
|
||||||
type: "readyReply",
|
type: "readyReply",
|
||||||
token: this.state.childToken,
|
token: this.state.childToken,
|
||||||
baseUrl: this.props.assetsBaseUrl,
|
baseUrl: assetsBaseUrl,
|
||||||
jsPath: this.props.jsPath,
|
jsPath: this.props.jsPath,
|
||||||
});
|
});
|
||||||
this.state.childReady = true;
|
this.state.childReady = true;
|
||||||
|
@ -261,7 +263,7 @@ const JSOutput = {
|
||||||
function getProps(hook) {
|
function getProps(hook) {
|
||||||
return {
|
return {
|
||||||
ref: getAttributeOrThrow(hook.el, "data-ref"),
|
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"),
|
jsPath: getAttributeOrThrow(hook.el, "data-js-path"),
|
||||||
sessionToken: getAttributeOrThrow(hook.el, "data-session-token"),
|
sessionToken: getAttributeOrThrow(hook.el, "data-session-token"),
|
||||||
sessionId: getAttributeOrThrow(hook.el, "data-session-id"),
|
sessionId: getAttributeOrThrow(hook.el, "data-session-id"),
|
||||||
|
|
|
@ -8,7 +8,7 @@ defmodule LivebookWeb.Output.JSComponent do
|
||||||
phx-hook="JSOutput"
|
phx-hook="JSOutput"
|
||||||
phx-update="ignore"
|
phx-update="ignore"
|
||||||
data-ref={@info.ref}
|
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-js-path={@info.assets.js_path}
|
||||||
data-session-token={session_token(@info.pid)}
|
data-session-token={session_token(@info.pid)}
|
||||||
data-session-id={@session_id}>
|
data-session-id={@session_id}>
|
||||||
|
|
Loading…
Add table
Reference in a new issue