fix(tabs): stop fallback outside locked window
This commit is contained in:
@@ -35,10 +35,15 @@ function normalizeAutomationWindowId(value) {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return null;
|
||||
}
|
||||
const numeric = Math.floor(Number(value));
|
||||
const numeric = Number(value);
|
||||
return Number.isInteger(numeric) && numeric >= 0 ? numeric : null;
|
||||
}
|
||||
|
||||
function buildAutomationWindowUnavailableError(error) {
|
||||
const suffix = error?.message ? ` 原因:${error.message}` : '';
|
||||
return new Error(`自动任务窗口已不可用,请在目标 Chrome 窗口重新打开侧边栏并启动任务。${suffix}`);
|
||||
}
|
||||
|
||||
async function createAutomationScopedTab(createProperties = {}, options = {}) {
|
||||
const windowId = normalizeAutomationWindowId(
|
||||
options?.automationWindowId
|
||||
@@ -55,8 +60,8 @@ async function createAutomationScopedTab(createProperties = {}, options = {}) {
|
||||
...(createProperties || {}),
|
||||
windowId,
|
||||
});
|
||||
} catch {
|
||||
return chrome.tabs.create(createProperties || {});
|
||||
} catch (error) {
|
||||
throw buildAutomationWindowUnavailableError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,8 +83,8 @@ async function queryAutomationScopedTabs(queryInfo = {}, options = {}) {
|
||||
delete scopedQuery.currentWindow;
|
||||
try {
|
||||
return await chrome.tabs.query(scopedQuery);
|
||||
} catch {
|
||||
return chrome.tabs.query(queryInfo || {});
|
||||
} catch (error) {
|
||||
throw buildAutomationWindowUnavailableError(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return null;
|
||||
}
|
||||
const numeric = Math.floor(Number(value));
|
||||
const numeric = Number(value);
|
||||
return Number.isInteger(numeric) && numeric >= 0 ? numeric : null;
|
||||
}
|
||||
|
||||
|
||||
@@ -23,10 +23,15 @@
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return null;
|
||||
}
|
||||
const numeric = Math.floor(Number(value));
|
||||
const numeric = Number(value);
|
||||
return Number.isInteger(numeric) && numeric >= 0 ? numeric : null;
|
||||
}
|
||||
|
||||
function buildAutomationWindowUnavailableError(error) {
|
||||
const suffix = error?.message ? ` 原因:${error.message}` : '';
|
||||
return new Error(`自动任务窗口已不可用,请在目标 Chrome 窗口重新打开侧边栏并启动任务。${suffix}`);
|
||||
}
|
||||
|
||||
async function getAutomationWindowId(options = {}) {
|
||||
const directWindowId = normalizeAutomationWindowId(
|
||||
options.automationWindowId ?? options.windowId ?? null
|
||||
@@ -58,8 +63,7 @@
|
||||
return await chrome.tabs.query(scopedQuery);
|
||||
} catch (error) {
|
||||
if (Object.prototype.hasOwnProperty.call(scopedQuery, 'windowId')) {
|
||||
await setState({ automationWindowId: null }).catch(() => {});
|
||||
return chrome.tabs.query(queryInfo || {});
|
||||
throw buildAutomationWindowUnavailableError(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@@ -76,8 +80,7 @@
|
||||
return await chrome.tabs.create(properties);
|
||||
} catch (error) {
|
||||
if (windowId !== null) {
|
||||
await setState({ automationWindowId: null }).catch(() => {});
|
||||
return chrome.tabs.create(createProperties || {});
|
||||
throw buildAutomationWindowUnavailableError(error);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user