feat(ext): handling page reload/redirect/close

This commit is contained in:
Simon
2026-01-21 18:46:50 +08:00
parent 570c79623b
commit 3fea74faa9
5 changed files with 250 additions and 18 deletions

View File

@@ -9,13 +9,13 @@
*/
import { PageController } from '@page-agent/page-controller'
import { pageControllerRPC } from '../messaging/protocol'
import { contentScriptQuery, pageControllerRPC } from '../messaging/protocol'
export default defineContentScript({
matches: ['<all_urls>'],
runAt: 'document_idle',
main() {
async main() {
console.log('[PageAgentExt] Content script loaded')
// Lazy-initialized controller - created on demand, disposed between tasks
@@ -40,6 +40,24 @@ export default defineContentScript({
}
)
// Check if there's an active task that needs mask to be shown
// This handles page reload/navigation during task execution
setTimeout(async () => {
try {
const shouldShowMask = await contentScriptQuery.sendMessage(
'content:shouldShowMask',
undefined
)
if (shouldShowMask) {
console.log('[PageAgentExt] Restoring mask after page reload')
await getController().showMask()
}
} catch (error) {
// Ignore errors - background may not be ready
console.log('[PageAgentExt] shouldShowMask check skipped:', error)
}
}, 100)
// Cleanup on page unload
window.addEventListener('beforeunload', () => {
controller?.dispose()