Skip to content

Commit

Permalink
Merge pull request #98 from Alokit-Innovations/akg/cors_for_api_calls
Browse files Browse the repository at this point in the history
CORS for api calls
  • Loading branch information
tapishr authored Mar 23, 2024
2 parents 68a3ca3 + 8780928 commit c294879
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
15 changes: 8 additions & 7 deletions backgroundScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,29 @@ 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",
"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 +64,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
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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",
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 c294879

Please sign in to comment.