aboutsummaryrefslogtreecommitdiff
path: root/ext/js/pages/common/extension-content-controller.js
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/pages/common/extension-content-controller.js')
-rw-r--r--ext/js/pages/common/extension-content-controller.js32
1 files changed, 28 insertions, 4 deletions
diff --git a/ext/js/pages/common/extension-content-controller.js b/ext/js/pages/common/extension-content-controller.js
index 3792130c..1c3f9c74 100644
--- a/ext/js/pages/common/extension-content-controller.js
+++ b/ext/js/pages/common/extension-content-controller.js
@@ -19,6 +19,7 @@
import {Environment} from '../../extension/environment.js';
export class ExtensionContentController {
+ /** */
prepare() {
this._prepareSpecialUrls();
this._prepareExtensionIdExamples();
@@ -27,6 +28,7 @@ export class ExtensionContentController {
// Private
+ /** */
async _prepareEnvironmentInfo() {
const {dataset} = document.documentElement;
const {manifest_version: manifestVersion} = chrome.runtime.getManifest();
@@ -40,6 +42,7 @@ export class ExtensionContentController {
dataset.os = platform.os;
}
+ /** */
_prepareExtensionIdExamples() {
const nodes = document.querySelectorAll('.extension-id-example');
let url = '';
@@ -53,8 +56,9 @@ export class ExtensionContentController {
}
}
+ /** */
_prepareSpecialUrls() {
- const nodes = document.querySelectorAll('[data-special-url]');
+ const nodes = /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('[data-special-url]'));
if (nodes.length === 0) { return; }
let extensionId = '';
@@ -77,16 +81,27 @@ export class ExtensionContentController {
}
}
+ /**
+ * @param {MouseEvent} e
+ */
_onSpecialUrlLinkClick(e) {
switch (e.button) {
case 0:
case 1:
- e.preventDefault();
- this._createTab(e.currentTarget.dataset.specialUrl, true);
+ {
+ const element = /** @type {HTMLElement} */ (e.currentTarget);
+ const {specialUrl} = element.dataset;
+ if (typeof specialUrl !== 'string') { return; }
+ e.preventDefault();
+ this._createTab(specialUrl, true);
+ }
break;
}
}
+ /**
+ * @param {MouseEvent} e
+ */
_onSpecialUrlLinkMouseDown(e) {
switch (e.button) {
case 0:
@@ -96,10 +111,17 @@ export class ExtensionContentController {
}
}
+ /**
+ * @param {string} url
+ * @param {boolean} useOpener
+ * @returns {Promise<chrome.tabs.Tab>}
+ */
async _createTab(url, useOpener) {
+ /** @type {number|undefined} */
let openerTabId;
if (useOpener) {
try {
+ /** @type {chrome.tabs.Tab|undefined} */
const tab = await new Promise((resolve, reject) => {
chrome.tabs.getCurrent((result) => {
const e = chrome.runtime.lastError;
@@ -110,7 +132,9 @@ export class ExtensionContentController {
}
});
});
- openerTabId = tab.id;
+ if (typeof tab !== 'undefined') {
+ openerTabId = tab.id;
+ }
} catch (e) {
// NOP
}