-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
27 lines (25 loc) · 1.12 KB
/
Copy pathbackground.js
File metadata and controls
27 lines (25 loc) · 1.12 KB
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
// background.js
chrome.runtime.onInstalled.addListener(() => {
console.log('Job Application Assistant extension installed.');
});
// Listen for tab updates to inject the content script if it hasn't been already.
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (changeInfo.status === 'complete' && tab.url && tab.url.startsWith('http')) {
chrome.scripting.executeScript({
target: { tabId: tabId },
func: () => window.hasOwnProperty('jobAssistantLoaded'),
}, (results) => {
// Check if the script has already been injected.
if (chrome.runtime.lastError || !results || results[0].result) {
return; // Already loaded or an error occurred.
}
// If not loaded, inject the content script.
chrome.scripting.executeScript({
target: { tabId: tabId },
files: ['content.js']
}).then(() => {
console.log('Injected content script into tab:', tabId);
}).catch(err => console.error('Failed to inject content script:', err));
});
}
});