-
Notifications
You must be signed in to change notification settings - Fork 0
/
contentScript.js
63 lines (56 loc) · 1.81 KB
/
contentScript.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
let readConsole = false;
var script
chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) {
if (message.type === "getLocalStorage") {
// Obtener el localStorage
const localStorageData = { ...localStorage }; // Copiar el localStorage a un objeto
// Enviar el localStorage al background script
chrome.runtime.sendMessage({
type: "localStorage",
data: localStorageData,
});
}else if(message.type === "startReadingConsole"){
readConsole = true;
window.addEventListener(
"message",
function (event) {
// Solo aceptamos mensajes de nosotros mismos
if (event.source != window) return;
if (event.data.type && event.data.type == "FROM_PAGE") {
chrome.runtime.sendMessage({
type: "consolelog",
data: event.data.logs,
});
}
},
false
);
}else if(message.type === "stopReadingConsole"){
window.postMessage({ type: "stopConsole"}, "*");
}
});
script = document.createElement("script");
script.src = chrome.runtime.getURL("inject.js");
(document.head || document.documentElement).appendChild(script);
script.onload = function () {
this.remove();
};
window.addEventListener("message", function (event) {
if(readConsole === true){
if(event.data.type === "FROM_PAGE_ERROR"){
let dataTosend = event.data.logs[1].stack !== undefined ? event.data.logs[1].stack : event.data.logs[1].message;
chrome.runtime.sendMessage({
type: "consoleError",
data: dataTosend,
});
}else if(event.data.type === "FROM_PAGE_LOG"){
let dataTosend = event.data.logs[0];
if(dataTosend !== ''){
chrome.runtime.sendMessage({
type: "consoleLog",
data: dataTosend,
});
}
}
}
})