Skip to content

Commit

Permalink
minor: formatting and bug fixes. IMP: removed CORS from install API c…
Browse files Browse the repository at this point in the history
…all because backend is not ready yet
  • Loading branch information
avikalpg committed Mar 23, 2024
1 parent 68a3ca3 commit a3664e2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
16 changes: 9 additions & 7 deletions backgroundScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,30 @@ chrome.runtime.onInstalled.addListener(() => {

// Store the website URL in Chrome's local storage.
chrome.storage.local.set({ websiteUrl }).then(_ => console.log(`Website URL set to ${websiteUrl};`))
.catch(error => console.error(`Failed to set website URL: ${error}`));
.catch(error => console.error(`Failed to set website URL: ${error}`));

// Make an API call to the backend to create a Rudderstack event when the extension is installed.
chrome.storage.local.get(["userId"]).then(({ userId }) => {
const body = {
userId: userId ? userId : "anonymous-id", // Use the stored userId or "anonymous-id" if not available.
function: 'chrome-extension-installed'
}
};
const url = `${websiteUrl}/api/extension/events`;
fetch(url, {
method: "POST",
headers: {
"Access-Control-Allow-Origin": "chrome-extension://jafgelpkkkopeaefadkdjcmnicgpcncc",
// "Access-Control-Allow-Origin": "chrome-extension://jafgelpkkkopeaefadkdjcmnicgpcncc",
"Content-Type": "application/json",
"Accept": "application/json",
},
body: JSON.stringify(body)
})
.then((response) => response.json())
.then((data) => dataFromAPI = data); // Store the response data in the dataFromAPI variable.
})
})
.then((data) => {
console.info(`[vibinex] Successfully sent installation event to backend. Response: ${JSON.stringify(data)}`);
}).catch(error => console.error(`[vibinex] Failed to send installation event to backend: ${error}`));;
});
});

/**
* Checks Logged in status for showing indicator on supported pages like github and bitbucket.
Expand Down Expand Up @@ -63,7 +65,7 @@ chrome.runtime.onMessage.addListener(
const message = JSON.parse(request.message);
if (message.action === "check_login_status") {
const websiteUrl = message.websiteUrl;
const provider = message.provider
const provider = message.provider;
checkLoginStatus(websiteUrl, provider).then(loggedIn => {
sendResponse({ status: loggedIn });
});
Expand Down
1 change: 0 additions & 1 deletion scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
* Note: This script assumes it's running in the context of a browser extension, given its use of the 'chrome.storage' API.
*/
console.log('[vibinex] Running content scripts');
'use strict';
window.onload = () => {
chrome.storage.local.get(["websiteUrl", "userId"]).then(async ({ websiteUrl, userId }) => {
console.log("We have the userId:", userId) // FIXME: remove this console.log
Expand Down

0 comments on commit a3664e2

Please sign in to comment.