Skip to content

Commit

Permalink
fix: Respect the mv2 popup type
Browse files Browse the repository at this point in the history
  • Loading branch information
aklinker1 committed Jun 25, 2023
1 parent 7945c94 commit 0f37ceb
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
10 changes: 10 additions & 0 deletions src/utils/findEntrypoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,10 @@ async function getPopupEntrypoint(

const content = await fs.readFile(path, 'utf-8');
const { document } = parseHTML(content);

const title = document.querySelector('title');
if (title != null) options.defaultTitle = title.textContent ?? undefined;

const defaultIconContent = document
.querySelector("meta[name='manifest.default_icon']")
?.getAttribute('content');
Expand All @@ -126,6 +128,14 @@ async function getPopupEntrypoint(
}
}

const mv2KeyContent = document
.querySelector("meta[name='manifest.type']")
?.getAttribute('content');
if (mv2KeyContent) {
options.mv2Key =
mv2KeyContent === 'page_action' ? 'page_action' : 'browser_action';
}

return {
type: 'popup',
name: 'popup',
Expand Down
8 changes: 6 additions & 2 deletions src/utils/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,14 +190,18 @@ function addEntrypoints(
config.outDir,
'.html',
);
const options: Manifest.ActionManifest = {
default_icon: popup.options.defaultIcon,
default_title: popup.options.defaultTitle,
};
if (manifest.manifest_version === 3) {
manifest.action = {
...popup.options,
...options,
default_popup,
};
} else {
manifest[popup.options.mv2Key ?? 'browser_action'] = {
...popup.options,
...options,
default_popup,
};
}
Expand Down

0 comments on commit 0f37ceb

Please sign in to comment.