From a3664e298b8486f46d84480012027664f91410cf Mon Sep 17 00:00:00 2001 From: Avikalp Kumar Gupta Date: Sat, 23 Mar 2024 11:50:56 +0530 Subject: [PATCH 1/2] minor: formatting and bug fixes. IMP: removed CORS from install API call because backend is not ready yet --- backgroundScript.js | 16 +++++++++------- scripts/init.js | 1 - 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/backgroundScript.js b/backgroundScript.js index 76154d0..f23f0a4 100644 --- a/backgroundScript.js +++ b/backgroundScript.js @@ -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. @@ -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 }); }); diff --git a/scripts/init.js b/scripts/init.js index 4d32498..e781e26 100644 --- a/scripts/init.js +++ b/scripts/init.js @@ -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 From 878092841a16255eb6c629d970fbc18433587e3f Mon Sep 17 00:00:00 2001 From: Avikalp Kumar Gupta Date: Sat, 23 Mar 2024 13:29:42 +0530 Subject: [PATCH 2/2] update manifest version. --- backgroundScript.js | 1 - manifest.json | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/backgroundScript.js b/backgroundScript.js index f23f0a4..fde6fbe 100644 --- a/backgroundScript.js +++ b/backgroundScript.js @@ -21,7 +21,6 @@ chrome.runtime.onInstalled.addListener(() => { fetch(url, { method: "POST", headers: { - // "Access-Control-Allow-Origin": "chrome-extension://jafgelpkkkopeaefadkdjcmnicgpcncc", "Content-Type": "application/json", "Accept": "application/json", }, diff --git a/manifest.json b/manifest.json index 297fa75..4c32b1c 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "Vibinex Code Review", - "version": "1.1.4", + "version": "1.1.5", "manifest_version": 3, "description": "Personalization and context for pull requests on GitHub & Bitbucket", "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsRm6EaBdHDBxVjt9o9WKeL9EDdz1X+knDAU5uoZaRsXTmWjslhJN9DhSd7/Ys4aJOSN+s+5/HnIHcKV63P4GYaUM5FhETHEWORHlwIgjcV/1h6wD6bNbvXi06gtiygE+yMrCzzD93/Z+41XrwMElYiW2U5owNpat2Yfq4p9FDX1uBJUKsRIMp6LbRQla4vAzH/HMUtHWmeuUsmPVzcq1b6uB1QmuJqIQ1GrntIHw3UBWUlqRZ5OtxI1DCP3knglvqz26WT5Pc4GBDNlcI9+3F0vhwqwHqrdyjZpIKZ7iaQzcrovOqUKuXs1J3hDtXq8WoJELIqfIisY7rhAvq6b8jQIDAQAB",