Skip to content

Commit

Permalink
add initial mv3 changes for renderer preload
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmaddock committed Sep 28, 2024
1 parent 1d922c1 commit 013b93f
Showing 1 changed file with 34 additions and 2 deletions.
36 changes: 34 additions & 2 deletions packages/electron-chrome-extensions/src/renderer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ export const injectExtensionAPIs = () => {
},
},

i18n: {
factory: (base) => {
return {
...base,
getUILanguage: () => 'en-US', // TODO: implement
}
},
},

notifications: {
factory: (base) => {
return {
Expand All @@ -289,6 +298,21 @@ export const injectExtensionAPIs = () => {
},
},

permissions: {
factory: (base) => {
return {
...base,
// TODO(mv3): implement
contains: () => Promise.resolve(true),
getAll: () => Promise.resolve({ permissions: [], origins: [] }),
remove: () => Promise.resolve(true),
request: () => Promise.resolve(true),
onAdded: new ExtensionEvent('permissions.onAdded'),
onRemoved: new ExtensionEvent('permissions.onRemoved'),
}
},
},

privacy: {
factory: (base) => {
return {
Expand Down Expand Up @@ -451,8 +475,16 @@ export const injectExtensionAPIs = () => {
contextBridge.exposeInMainWorld('electron', electronContext)

// Mutate global 'chrome' object with additional APIs in the main world.
webFrame.executeJavaScript(`(${mainWorldScript}());`)
} catch {
const script = `(${mainWorldScript}());`;
if (process.type === 'renderer') {
webFrame.executeJavaScript(script);
// TODO(mv3): remove anys
} else if ((process as any).type === 'preload_realm') {
(contextBridge as any).evaluateInMainWorld(script);
}
} catch (error) {
console.error(error);

// contextBridge threw an error which means we're in the main world so we
// can just execute our function.
mainWorldScript()
Expand Down

0 comments on commit 013b93f

Please sign in to comment.