spot: more fixes for network, reinit stage for content script

This commit is contained in:
nick-delirium 2025-01-24 09:57:52 +01:00 committed by Delirium
parent c6299c4592
commit ce525a4ccf
5 changed files with 28 additions and 12 deletions

View file

@ -350,7 +350,6 @@ export default defineBackground(() => {
void attachDebuggerToTab(recordingState.activeTabId)
})
} else {
console.log(settings.useDebugger, 'tab', recordingState.activeTabId)
startTrackingNetwork();
}
}
@ -360,6 +359,7 @@ export default defineBackground(() => {
activeTabId: recordingState.activeTabId,
area: "tab",
recording: REC_STATE.recording,
audioPerm: recordingState.audioPerm,
};
const microphone = request.mic;
micStatus = microphone ? "on" : "off";
@ -401,6 +401,7 @@ export default defineBackground(() => {
activeTabId: null,
area: "desktop",
recording: REC_STATE.recording,
audioPerm: recordingState.audioPerm
};
startRecording(
recArea,
@ -588,6 +589,7 @@ export default defineBackground(() => {
activeTabId: null,
area: null,
recording: REC_STATE.stopped,
audioPerm: recordingState.audioPerm
};
}
if (request.type === messages.content.from.restart) {
@ -849,6 +851,7 @@ export default defineBackground(() => {
activeTabId: null,
area: null,
recording: REC_STATE.stopped,
audioPerm: recordingState.audioPerm
};
// id of spot, mobURL - for events, videoURL - for video
if (!resp || !resp.id) {
@ -934,14 +937,16 @@ export default defineBackground(() => {
active: true,
});
}
// in future:
// const tabs = await browser.tabs.query({}) as chrome.tabs.Tab[]
// for (const tab of tabs) {
// if (tab.id) {
// this will require more permissions, do we even want this?
// void chrome.tabs.executeScript(tab.id, {file: "content"});
// }
// }
for (const tab of await chrome.tabs.query({})) {
if (tab.url?.match(/(chrome|chrome-extension):\/\//gi)) {
continue;
}
const res = await browser.scripting.executeScript({
target: { tabId: tab.id },
files: ["/content-scripts/content.js"],
});
console.log('restoring content at', res)
}
await checkTokenValidity();
await initializeOffscreenDocument();
});
@ -1073,6 +1078,7 @@ export default defineBackground(() => {
activeTabId: null,
area: null,
recording: REC_STATE.stopped,
audioPerm: recordingState.audioPerm
};
void sendToActiveTab({
type: messages.content.to.unmount,
@ -1084,7 +1090,7 @@ export default defineBackground(() => {
return;
}
const mountMsg = {
type: "content:start",
type: messages.content.to.start,
microphone,
time: 0,
slackChannels,
@ -1119,6 +1125,7 @@ export default defineBackground(() => {
state: getRecState(),
activeTabId: null,
};
console.log(tabId, 'activation for new')
attachDebuggerToTab(tabId)
void sendToActiveTab(msg);
});
@ -1190,6 +1197,7 @@ export default defineBackground(() => {
activeTabId: null,
area: null,
recording: REC_STATE.stopped,
audioPerm: recordingState.audioPerm
};
}
}

View file

@ -16,6 +16,10 @@ export default defineContentScript({
cssInjectionMode: "ui",
async main(ctx) {
if (!ctx.isValid) {
console.error("Spot: context is invalidated on mount")
return;
}
const ui = await createShadowRootUi(ctx, {
name: "spot-ui",
position: "inline",

View file

@ -2,7 +2,7 @@
"name": "spot",
"description": "manifest.json description",
"private": true,
"version": "1.0.15",
"version": "1.0.16",
"type": "module",
"scripts": {
"dev": "wxt",

View file

@ -105,6 +105,7 @@ function createSpotNetworkRequest(
responseBody: "",
requestHeaders,
responseHeaders,
time: trackedRequest.timeStamp,
timestamp: trackedRequest.timeStamp,
statusCode: status,
error: trackedRequest.error,

View file

@ -16,7 +16,7 @@ export default defineConfig({
},
web_accessible_resources: [
{
resources: ["injected.js", "notifications.js"],
resources: ["injected.js", "notifications.js", "/content-scripts/content.css"],
matches: ["<all_urls>"],
},
],
@ -31,4 +31,7 @@ export default defineConfig({
"debugger",
],
},
runner: {
chromiumArgs: ['--user-data-dir=./.wxt/chrome-data'],
}
});