-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable network re-writing on chrome extension
this means we no longer need special configs for the extension
- Loading branch information
1 parent
328d128
commit bc8a564
Showing
7 changed files
with
80 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// learned from page-assist and ollama-ui | ||
|
||
export const rewriteChromeUrl = async (host?: string) => { | ||
if (__TARGET__ !== 'chrome' || !host) return | ||
|
||
if (typeof chrome !== 'undefined' && chrome.runtime && chrome.runtime.id) { | ||
const url = new URL(host) | ||
|
||
const domains = [url.hostname] | ||
const nextOrigin = `${url.protocol}//${url.hostname}` | ||
|
||
const rules = [ | ||
{ | ||
id: 1, | ||
condition: { | ||
requestDomains: domains, | ||
}, | ||
action: { | ||
type: 'modifyHeaders', | ||
requestHeaders: [ | ||
{ | ||
header: 'origin', | ||
operation: 'set', | ||
value: nextOrigin, | ||
}, | ||
], | ||
}, | ||
}, | ||
] | ||
|
||
console.log('rewriteChromeUrl', url) | ||
|
||
await chrome.declarativeNetRequest.updateDynamicRules({ | ||
removeRuleIds: rules.map(r => r.id), | ||
// @ts-expect-error this works properly | ||
addRules: rules, | ||
}) | ||
|
||
if(url.hostname === 'localhost') { | ||
await rewriteChromeUrl(`${url.protocol}//127.0.0.1`) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/// <reference types="vite/client" /> | ||
/// <reference types="vite-plugin-comlink/client" /> | ||
/// <reference types="chrome"/> | ||
|
||
declare const __TARGET__: 'pwa' | 'chrome' | 'firefox' |