Commit 81469b9f authored by Alejandro Celaya's avatar Alejandro Celaya Committed by Alejandro Celaya

Check browser extension config only for host frames

parent fa8f884b
...@@ -22,19 +22,9 @@ if (isBrowserSupported()) { ...@@ -22,19 +22,9 @@ if (isBrowserSupported()) {
const config = /** @type {AnnotatorConfig|SidebarAppConfig} */ ( const config = /** @type {AnnotatorConfig|SidebarAppConfig} */ (
parseJsonConfig(document) parseJsonConfig(document)
); );
// When the boot script is executed from the browser extension, a config
// generated by that specific extension is required
const extensionId = getExtensionId();
if (extensionId && !hasExtensionConfig(extensionId)) {
throw new Error(
'Could not start Hypothesis extension as configuration is missing'
);
}
const assetRoot = processUrlTemplate(config.assetRoot || '__ASSET_ROOT__'); const assetRoot = processUrlTemplate(config.assetRoot || '__ASSET_ROOT__');
// Check whether this is the sidebar app (indicated by the presence of a // Check whether this is a mini-app (indicated by the presence of a
// `<hypothesis-app>` element) and load the appropriate part of the client. // `<hypothesis-app>` element) and load the appropriate part of the client.
if (document.querySelector('hypothesis-app')) { if (document.querySelector('hypothesis-app')) {
const sidebarConfig = /** @type {SidebarAppConfig} */ (config); const sidebarConfig = /** @type {SidebarAppConfig} */ (config);
...@@ -44,6 +34,15 @@ if (isBrowserSupported()) { ...@@ -44,6 +34,15 @@ if (isBrowserSupported()) {
apiUrl: sidebarConfig.apiUrl, apiUrl: sidebarConfig.apiUrl,
}); });
} else { } else {
// When the boot script is executed from the browser extension on a host
// frame, a config generated by that specific extension is required
const extensionId = getExtensionId();
if (extensionId && !hasExtensionConfig(extensionId)) {
throw new Error(
'Could not start Hypothesis extension as configuration is missing'
);
}
// nb. If new asset URLs are added here, the browser extension and // nb. If new asset URLs are added here, the browser extension and
// `hypothesis-injector.ts` need to be updated. // `hypothesis-injector.ts` need to be updated.
const annotatorConfig = /** @type {AnnotatorConfig} */ (config); const annotatorConfig = /** @type {AnnotatorConfig} */ (config);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment