fix(ext): init without initialTab throws error
This commit is contained in:
@@ -75,6 +75,7 @@ export class MultiPageAgent extends PageAgentCore {
|
|||||||
},
|
},
|
||||||
|
|
||||||
onBeforeStep: async (agent) => {
|
onBeforeStep: async (agent) => {
|
||||||
|
if (!tabsController.currentTabId) return
|
||||||
// make sure the current tab is loaded before the step starts
|
// make sure the current tab is loaded before the step starts
|
||||||
await tabsController.waitUntilTabLoaded(tabsController.currentTabId!)
|
await tabsController.waitUntilTabLoaded(tabsController.currentTabId!)
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -58,8 +58,6 @@ export class RemotePageController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getBrowserState(): Promise<BrowserState> {
|
async getBrowserState(): Promise<BrowserState> {
|
||||||
if (!this.currentTabId) throw new Error('tabsController not initialized.')
|
|
||||||
|
|
||||||
let browserState = {} as BrowserState
|
let browserState = {} as BrowserState
|
||||||
debug('getBrowserState', this.currentTabId)
|
debug('getBrowserState', this.currentTabId)
|
||||||
|
|
||||||
@@ -178,7 +176,7 @@ interface DomActionReturn {
|
|||||||
/**
|
/**
|
||||||
* Check if a URL can run content scripts.
|
* Check if a URL can run content scripts.
|
||||||
*/
|
*/
|
||||||
function isContentScriptAllowed(url: string | undefined): boolean {
|
export function isContentScriptAllowed(url: string | undefined): boolean {
|
||||||
if (!url) return false
|
if (!url) return false
|
||||||
|
|
||||||
const restrictedPatterns = [
|
const restrictedPatterns = [
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
import { isContentScriptAllowed } from './RemotePageController'
|
||||||
|
|
||||||
const PREFIX = '[TabsController]'
|
const PREFIX = '[TabsController]'
|
||||||
|
|
||||||
function debug(...messages: any[]) {
|
function debug(...messages: any[]) {
|
||||||
@@ -49,14 +51,15 @@ export class TabsController extends EventTarget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (includeInitialTab) {
|
if (includeInitialTab) {
|
||||||
this.currentTabId = this.initialTabId
|
|
||||||
|
|
||||||
const info = await sendMessage({
|
const info = await sendMessage({
|
||||||
type: 'TAB_CONTROL',
|
type: 'TAB_CONTROL',
|
||||||
action: 'get_tab_info',
|
action: 'get_tab_info',
|
||||||
payload: { tabId: this.initialTabId },
|
payload: { tabId: this.initialTabId },
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if (isContentScriptAllowed(info.url)) {
|
||||||
|
this.currentTabId = this.initialTabId
|
||||||
|
|
||||||
this.tabs.push({
|
this.tabs.push({
|
||||||
id: result.tabId,
|
id: result.tabId,
|
||||||
isInitial: true,
|
isInitial: true,
|
||||||
@@ -67,6 +70,7 @@ export class TabsController extends EventTarget {
|
|||||||
|
|
||||||
await this.createTabGroup([this.initialTabId])
|
await this.createTabGroup([this.initialTabId])
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
await this.updateCurrentTabId(this.currentTabId)
|
await this.updateCurrentTabId(this.currentTabId)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user