mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-09 09:09:58 +00:00
Fix __onGCastApiAvailable being called early
This commit is contained in:
@@ -35,3 +35,15 @@ export function getWindowCenteredProps (
|
||||
|
||||
// tslint:disable-next-line:max-line-length
|
||||
export const REMOTE_MATCH_PATTERN_REGEX = /^(?:(?:(\*|https?|ftp):\/\/(\*|(?:\*\.(?:[^\/\*:]\.?)+(?:[^\.])|[^\/\*:]*))?)(\/.*)|<all_urls>)$/;
|
||||
|
||||
|
||||
export function loadScript (
|
||||
scriptUrl: string
|
||||
, doc: Document = document): HTMLScriptElement {
|
||||
|
||||
const scriptElement = doc.createElement("script");
|
||||
scriptElement.src = scriptUrl;
|
||||
(doc.head || doc.documentElement).append(scriptElement);
|
||||
|
||||
return scriptElement;
|
||||
}
|
||||
|
||||
@@ -47,6 +47,6 @@
|
||||
]
|
||||
, "web_accessible_resources": [
|
||||
"shim/bundle.js"
|
||||
, "vendor/webcomponents-lite.min.js"
|
||||
, "vendor/webcomponents-lite.js"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -3,12 +3,11 @@
|
||||
import { Message } from "../types";
|
||||
import { onMessageResponse, sendMessage } from "./messageBridge";
|
||||
|
||||
import { loadScript } from "../lib/utils";
|
||||
|
||||
|
||||
if ((window as any)._isFramework) {
|
||||
const polyfillScriptElement = document.createElement("script");
|
||||
polyfillScriptElement.src = browser.runtime.getURL(
|
||||
"vendor/webcomponents-lite.js")
|
||||
document.head.append(polyfillScriptElement);
|
||||
loadScript(browser.runtime.getURL("vendor/webcomponents-lite.js"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,6 +4,8 @@ import * as cast from "./cast";
|
||||
|
||||
import { onMessage } from "./messageBridge";
|
||||
|
||||
import { loadScript } from "../lib/utils";
|
||||
|
||||
|
||||
const _window = (window as any);
|
||||
|
||||
@@ -18,7 +20,7 @@ const CAST_FRAMEWORK_SCRIPT_URL =
|
||||
"https://www.gstatic.com/cast/sdk/libs/sender/1.0/cast_framework.js";
|
||||
|
||||
let bridgeInfo: any;
|
||||
let scriptLoaded = false;
|
||||
let isFramework = false;
|
||||
|
||||
// Call page's API loaded function if defined
|
||||
function callPageReadyFunction () {
|
||||
@@ -45,16 +47,11 @@ if (document.currentScript) {
|
||||
_window.cast = {};
|
||||
}
|
||||
|
||||
const scriptElement = document.createElement("script");
|
||||
scriptElement.src = CAST_FRAMEWORK_SCRIPT_URL;
|
||||
(document.head || document.documentElement).append(scriptElement);
|
||||
isFramework = true;
|
||||
|
||||
scriptElement.addEventListener("load", ev => {
|
||||
if (bridgeInfo) {
|
||||
callPageReadyFunction();
|
||||
}
|
||||
|
||||
scriptLoaded = true;
|
||||
const script = loadScript(CAST_FRAMEWORK_SCRIPT_URL);
|
||||
script.addEventListener("load", ev => {
|
||||
callPageReadyFunction();
|
||||
});
|
||||
|
||||
/*
|
||||
@@ -72,7 +69,7 @@ onMessage(message => {
|
||||
case "shim:/initialized": {
|
||||
bridgeInfo = message.data;
|
||||
|
||||
if (!scriptLoaded) {
|
||||
if (!isFramework) {
|
||||
callPageReadyFunction();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user