Skip to content

Commit ebd566c

Browse files
committed
FIx reinjection after error
1 parent 0caf986 commit ebd566c

File tree

4 files changed

+34
-14
lines changed

4 files changed

+34
-14
lines changed

src/background/background.js

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,26 @@ async function handleGreasyForkInstall(url) {
194194
}
195195

196196
async function handleCrossOriginXmlhttpRequest(details, tabId, sendResponse) {
197+
const { url, method = "GET", headers, data } = details;
198+
199+
if (!url) {
200+
console.error("CodeTweak: Cross-origin XMLHttprequest failed: No URL provided.");
201+
sendResponse({ error: "No URL provided." });
202+
return;
203+
}
204+
205+
const requestOptions = {
206+
method,
207+
headers,
208+
};
209+
210+
// Only add body for methods that support it
211+
if (data && !["GET", "HEAD"].includes(method.toUpperCase())) {
212+
requestOptions.body = data;
213+
}
214+
197215
try {
198-
const response = await fetch(details.url, {
199-
method: details.method || "GET",
200-
headers: details.headers,
201-
body: details.data,
202-
});
216+
const response = await fetch(url, requestOptions);
203217

204218
const responseHeaders = {};
205219
response.headers.forEach((value, name) => {
@@ -242,7 +256,12 @@ async function handleCrossOriginXmlhttpRequest(details, tabId, sendResponse) {
242256
};
243257
sendResponse({ result });
244258
} catch (error) {
245-
console.error("CodeTweak: Cross-origin XMLHttprequest failed:", error);
259+
console.error("CodeTweak: Cross-origin XMLHttprequest failed:", {
260+
error: error,
261+
url: url,
262+
method: method,
263+
headers: headers
264+
});
246265
sendResponse({ error: error.message });
247266
}
248267
}
@@ -307,7 +326,12 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
307326
console.log("[CodeTweak] Message received:", message.type || message.action);
308327

309328
if (message.type === "GM_API_REQUEST") {
310-
const { action, payload } = message.payload;
329+
if (!message.payload) {
330+
console.error("[CodeTweak] GM_API_REQUEST received with no payload.");
331+
sendResponse({ error: "Request payload is missing." });
332+
return true;
333+
}
334+
const { action, ...payload } = message.payload;
311335

312336
if (action === "xmlhttpRequest") {
313337
// Still not working properly....
@@ -406,7 +430,9 @@ chrome.runtime.onConnect.addListener((port) => {
406430
const navigationEvents = ["onCommitted", "onDOMContentLoaded", "onCompleted"];
407431
navigationEvents.forEach((event, index) => {
408432
chrome.webNavigation[event].addListener((details) => {
409-
console.log(`CodeTweak: webNavigation.${event} event fired for tab ${details.tabId}`, details);
433+
if (event === "onCommitted" && details.frameId === 0) {
434+
clearInjectedCoreScriptsForTab(details.tabId);
435+
}
410436
injectScriptsForStage(
411437
details,
412438
Object.values(INJECTION_TYPES)[index],

src/dashboard/dashboard.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ function setupFileDragAndDrop() {
183183
}
184184

185185
async function exportAllScripts() {
186-
console.log("Exporting all scripts");
187186
try {
188187
const { scripts = [] } = await chrome.storage.local.get("scripts");
189188
if (!scripts.length) {

src/utils/elementSelector.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,6 @@ if (target) {
605605
async copyToClipboard(text) {
606606
try {
607607
await navigator.clipboard.writeText(text);
608-
console.log('CodeTweak: Selector copied to clipboard');
609608
} catch (error) {
610609
console.debug('CodeTweak: Clipboard write failed', error);
611610
this.fallbackCopyToClipboard(text);
@@ -623,7 +622,6 @@ if (target) {
623622

624623
try {
625624
document.execCommand('copy');
626-
console.log('CodeTweak: Selector copied to clipboard (fallback)');
627625
} catch (error) {
628626
console.debug('CodeTweak: Fallback copy failed', error);
629627
}

src/utils/inject.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ function createMainWorldExecutor(
9393
window._executedScriptIds = window._executedScriptIds || new Set();
9494

9595
if (window._executedScriptIds.has(scriptId)) {
96-
console.log(`CodeTweak: Script ${scriptId} already executed`);
9796
return true;
9897
}
9998

@@ -187,7 +186,6 @@ function createIsolatedWorldExecutor(
187186
window._executedScriptIds = window._executedScriptIds || new Set();
188187

189188
if (window._executedScriptIds.has(scriptId)) {
190-
console.log(`CodeTweak: Script ${scriptId} already executed`);
191189
return true;
192190
}
193191

@@ -288,7 +286,6 @@ class ScriptInjector {
288286
? createMainWorldExecutor
289287
: createIsolatedWorldExecutor;
290288

291-
console.log(`CodeTweak: Executing script '${config.id}' in ${world} world.`);
292289
await chrome.scripting.executeScript({
293290
target: { tabId },
294291
world,

0 commit comments

Comments
 (0)