Update types.ts
This commit is contained in:
@@ -385,6 +385,7 @@ async function attachTab(tabId: number): Promise<Protocol.Target.TargetInfo> {
|
|||||||
)) as Protocol.Target.GetTargetInfoResponse
|
)) as Protocol.Target.GetTargetInfoResponse
|
||||||
|
|
||||||
const targetInfo = result.targetInfo
|
const targetInfo = result.targetInfo
|
||||||
|
const attachOrder = nextSessionId
|
||||||
const sessionId = `pw-tab-${nextSessionId++}`
|
const sessionId = `pw-tab-${nextSessionId++}`
|
||||||
|
|
||||||
store.setState((state) => {
|
store.setState((state) => {
|
||||||
@@ -393,6 +394,7 @@ async function attachTab(tabId: number): Promise<Protocol.Target.TargetInfo> {
|
|||||||
sessionId,
|
sessionId,
|
||||||
targetId: targetInfo.targetId,
|
targetId: targetInfo.targetId,
|
||||||
state: 'connected',
|
state: 'connected',
|
||||||
|
attachOrder,
|
||||||
})
|
})
|
||||||
return { tabs: newTabs, connectionState: 'connected', errorText: undefined }
|
return { tabs: newTabs, connectionState: 'connected', errorText: undefined }
|
||||||
})
|
})
|
||||||
@@ -1025,6 +1027,12 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
|
|||||||
|
|
||||||
const name = `playwriterPinnedElem${count}`
|
const name = `playwriterPinnedElem${count}`
|
||||||
|
|
||||||
|
const connectedTabs = Array.from(store.getState().tabs.entries())
|
||||||
|
.filter(([_, t]) => t.state === 'connected')
|
||||||
|
.sort((a, b) => (a[1].attachOrder ?? 0) - (b[1].attachOrder ?? 0))
|
||||||
|
const pageIndex = connectedTabs.findIndex(([id]) => id === tab.id)
|
||||||
|
const hasMultiplePages = connectedTabs.length > 1
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const result = (await chrome.debugger.sendCommand(debuggee, 'Runtime.evaluate', {
|
const result = (await chrome.debugger.sendCommand(debuggee, 'Runtime.evaluate', {
|
||||||
expression: `
|
expression: `
|
||||||
@@ -1043,6 +1051,10 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const clipboardText = hasMultiplePages
|
||||||
|
? `globalThis.${name} (page ${pageIndex}, ${tab.url || 'unknown url'})`
|
||||||
|
: `globalThis.${name}`
|
||||||
|
|
||||||
await chrome.debugger.sendCommand(debuggee, 'Runtime.evaluate', {
|
await chrome.debugger.sendCommand(debuggee, 'Runtime.evaluate', {
|
||||||
expression: `
|
expression: `
|
||||||
(() => {
|
(() => {
|
||||||
@@ -1051,7 +1063,7 @@ chrome.contextMenus.onClicked.addListener(async (info, tab) => {
|
|||||||
const orig = el.getAttribute('style') || '';
|
const orig = el.getAttribute('style') || '';
|
||||||
el.setAttribute('style', orig + '; outline: 3px solid #22c55e !important; outline-offset: 2px !important; box-shadow: 0 0 0 3px #22c55e !important;');
|
el.setAttribute('style', orig + '; outline: 3px solid #22c55e !important; outline-offset: 2px !important; box-shadow: 0 0 0 3px #22c55e !important;');
|
||||||
setTimeout(() => el.setAttribute('style', orig), 300);
|
setTimeout(() => el.setAttribute('style', orig), 300);
|
||||||
return navigator.clipboard.writeText('globalThis.${name}');
|
return navigator.clipboard.writeText(${JSON.stringify(clipboardText)});
|
||||||
})()
|
})()
|
||||||
`,
|
`,
|
||||||
awaitPromise: true,
|
awaitPromise: true,
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ export interface TabInfo {
|
|||||||
state: TabState
|
state: TabState
|
||||||
errorText?: string
|
errorText?: string
|
||||||
pinnedCount?: number
|
pinnedCount?: number
|
||||||
|
attachOrder?: number
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExtensionState {
|
export interface ExtensionState {
|
||||||
|
|||||||
Reference in New Issue
Block a user