Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
elg0nz committed Apr 24, 2024
1 parent 50b8424 commit 98d3975
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
2 changes: 2 additions & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
auto-install-peers = true
package-manager-strict = false
29 changes: 18 additions & 11 deletions apps/owlserver-chrome/src/background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,30 +37,33 @@ chrome.runtime.onMessage.addListener(

// FIXME: check recordingState
if (request.message === "wrapperToBackground") {
if (request.data.length > 0) {
if (request.data.length > 0) {
buffer.push(request.data);
}
sendResponse({ message: "backgroundToPopup", status: "ok" });
return
return;
}
sendResponse({ message: request.message, status: "pending" });
},
);


chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === "complete") {
const dataUnencoded = { tabId, url: tab.url, title: tab.title };
const data = btoa(JSON.stringify(dataUnencoded));

const payload = { dataType: "tab_data", data: data, timestamp: nowTimestampB() };
const payload = {
dataType: "tab_data",
data: data,
timestamp: nowTimestampB(),
};
webSocket.send(JSON.stringify(payload));
}
});

let webSocket = new WebSocket('ws://localhost:8080/ws');
let webSocket = new WebSocket("ws://localhost:8080/ws");
webSocket.onopen = (event) => {
console.log('websocket open');
console.log("websocket open");
keepAlive();
};

Expand All @@ -69,7 +72,7 @@ webSocket.onmessage = (event) => {
};

webSocket.onclose = (event) => {
console.log('websocket connection closed');
console.log("websocket connection closed");
webSocket = null;
};

Expand All @@ -90,7 +93,7 @@ function keepAlive() {
}
},
// Set the interval to 20 seconds to prevent the service worker from becoming inactive.
20 * 1000
20 * 1000,
);
}

Expand All @@ -100,14 +103,18 @@ function nowTimestampB(): number {
}

function sendDataToServer(): void {
console.log('sending data to server');
console.log("sending data to server");
buffer.map((data) => {
const payload = { dataType: "bData", data: data, timestamp: nowTimestampB() };
const payload = {
dataType: "bData",
data: data,
timestamp: nowTimestampB(),
};
webSocket.send(JSON.stringify(payload));
});

buffer.length = 0; // Clear the buffer after sending the data
}

// send data every 2 seconds
setInterval(sendDataToServer, 2000);
setInterval(sendDataToServer, 2000);
20 changes: 12 additions & 8 deletions apps/owlserver-chrome/src/wrappers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function sendToBackground(data: string, dataType: string) {
jsonHolder.type = "application/json";
jsonHolder.id = "jsonHolder";
const timestamp = nowTimestamp();
const payload = { dataType, data: data, timestamp }
const payload = { dataType, data: data, timestamp };

const b64encoded = btoa(JSON.stringify(payload)) as string;

Expand Down Expand Up @@ -53,7 +53,9 @@ function stringifyEventTarget(event: Event): string {
targetInfo.className = (event.target as Element).className; // Class names of the element

// Collect attributes in a serializable object
targetInfo.attributes = Array.from((event.target as Element).attributes).reduce((attrs, attr) => {
targetInfo.attributes = Array.from(
(event.target as Element).attributes,
).reduce((attrs, attr) => {
attrs[attr.name] = attr.value;
return attrs;
}, {});
Expand All @@ -64,10 +66,10 @@ function stringifyEventTarget(event: Event): string {
}

function sendTagsToServer() {
const scriptTags = document.querySelectorAll('script');
const scriptTags = document.querySelectorAll("script");
// Loop through scriptTags and access their attributes (e.g., src)
// biome-ignore lint/complexity/noForEach: <explanation>
scriptTags.forEach((scriptTag) => {
scriptTags.forEach((scriptTag) => {
const scriptSrc = scriptTag.src;
const payload = {
event_type: "script_tag_found",
Expand All @@ -76,10 +78,10 @@ function sendTagsToServer() {
sendToBackground(JSON.stringify(payload), "tags");
});

const linkTags = document.querySelectorAll('link');
const linkTags = document.querySelectorAll("link");
// Loop through linkTags and access their attributes (e.g., href)
// biome-ignore lint/complexity/noForEach: <explanation>
linkTags.forEach((linkTag) => {
linkTags.forEach((linkTag) => {
const linkHref = linkTag.href;
const payload = {
event_type: "link_tag_found",
Expand All @@ -89,7 +91,6 @@ function sendTagsToServer() {
});
}


document.addEventListener("click", (event: MouseEvent) => {
const payload = {
event_type: event.type,
Expand Down Expand Up @@ -189,7 +190,10 @@ observer.observe(document.body, {
const arr = this.responseText;

sendToBackground(this._url, "request_url");
sendToBackground(JSON.parse(this._requestHeaders), "request_headers");
sendToBackground(
JSON.parse(this._requestHeaders),
"request_headers",
);
sendToBackground(responseHeaders, "response_headers");
sendToBackground(JSON.parse(arr), "response_body");
} catch (err) {
Expand Down

0 comments on commit 98d3975

Please sign in to comment.