forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 1
/
background.js
31 lines (30 loc) · 1.18 KB
/
background.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
// Exchange data with Flask
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
let page_url = request.url;
// Connect to the scraper
fetch("http://127.0.0.1:5000/get_url", {
method: 'POST',
mode: 'cors',
body: JSON.stringify({
'page_url': page_url
}),
headers: {
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then(function(response) { // Collect the response
let review_tags = response.tags
// Dynamically set the tags
chrome.storage.sync.set({ tags: review_tags },
function() { // logging
console.log(`[INFO][background.js] tags for this web page now set to ${review_tags}`);
});
// Log the success message
console.log('Success:', response.success, response.status)
})
.catch(error => console.error('Error:', error));
sendResponse({ status: "Got url in the backend" });
}
);