-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(browser): migrate from webextension-toolbox to WXT framework #859
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
89a0681
49a2535
f3292e9
2efbee6
6b2f710
86e697d
96a6c17
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,8 @@ yarn-error.log* | |
| # Build output | ||
| dist/ | ||
| packages/ | ||
| .output/ | ||
| .wxt/ | ||
|
|
||
| # Environment variables | ||
| .env | ||
|
|
||
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| export default defineBackground(() => { | ||
| const injectContentToTab = async (tab: chrome.tabs.Tab): Promise<void> => { | ||
| // Skip if URL is undefined | ||
| if (!tab.url) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if tab is discarded | ||
| if (tab.discarded) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if tab ID is undefined | ||
| if (tab.id === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| // Skip if not a GitHub URL | ||
| if (!tab.url.startsWith('https://github.com/')) { | ||
| return; | ||
| } | ||
|
|
||
| try { | ||
| const manifest = chrome.runtime.getManifest(); | ||
|
|
||
| // Inject CSS | ||
| if (manifest.content_scripts?.[0]?.css) { | ||
| await chrome.scripting.insertCSS({ | ||
| target: { tabId: tab.id }, | ||
| files: manifest.content_scripts[0].css, | ||
| }); | ||
| } | ||
|
|
||
| // Inject JavaScript | ||
| if (manifest.content_scripts?.[0]?.js) { | ||
| await chrome.scripting.executeScript({ | ||
| target: { tabId: tab.id }, | ||
| files: manifest.content_scripts[0].js, | ||
| }); | ||
| } | ||
| } catch (error) { | ||
| console.error('Error injecting content script:', error); | ||
| } | ||
|
yamadashy marked this conversation as resolved.
|
||
| }; | ||
|
|
||
| // Update extension content for tabs | ||
| chrome.tabs.query({}, async (tabs: chrome.tabs.Tab[]) => { | ||
| for (const tab of tabs) { | ||
| try { | ||
| await injectContentToTab(tab); | ||
| } catch (e) { | ||
| console.error(e); | ||
| } | ||
| } | ||
| }); | ||
|
yamadashy marked this conversation as resolved.
yamadashy marked this conversation as resolved.
Comment on lines
+47
to
+55
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The current code iterates through tabs and injects scripts sequentially using chrome.tabs.query({}, (tabs: chrome.tabs.Tab[]) => {
// Process tabs in parallel for faster startup.
tabs.forEach((tab) => injectContentToTab(tab));
}); |
||
| }); | ||
Uh oh!
There was an error while loading. Please reload this page.