1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-17 16:53:34 +00:00

[PM-10667] Implement manifest v3 POC for remaining browsers (#10419)

* [PM-10667] Implement manifest v3 on Firefox and Safari

* [PM-10667] Fixing issues with CORS present in sandboxed iframe on Firefox

* [PM-10667] Updating gulp build process to ensure dist files are created correctly

* [PM-10667] Adding build processes to the Github workflow

* [PM-10667] Removing faulty Safari mv3 build workflow

* [PM-10667] Fixing jest tests

* [PM-10667] Reworking logic within inline menu

* Update apps/browser/webpack.config.js

Co-authored-by: Jonathan Prusik <jprusik@users.noreply.github.com>

---------

Co-authored-by: Jonathan Prusik <jprusik@users.noreply.github.com>
This commit is contained in:
Cesar Gonzalez
2024-08-15 09:54:18 -05:00
committed by GitHub
parent 72767dec74
commit 8fbdd8d22e
16 changed files with 608 additions and 43 deletions

View File

@@ -13,6 +13,52 @@ if (process.env.NODE_ENV == null) {
}
const ENV = (process.env.ENV = process.env.NODE_ENV);
const manifestVersion = process.env.MANIFEST_VERSION == 3 ? 3 : 2;
const browser = process.env.BROWSER;
function modifyManifestV3(buffer) {
if (manifestVersion === 2 || !browser) {
return buffer;
}
const manifest = JSON.parse(buffer.toString());
if (browser === "chrome") {
// Remove unsupported properties
delete manifest.applications;
delete manifest.sidebar_action;
delete manifest.commands._execute_sidebar_action;
return JSON.stringify(manifest, null, 2);
}
// Update the background script reference to be an event page
const backgroundScript = manifest.background.service_worker;
delete manifest.background.service_worker;
manifest.background.scripts = [backgroundScript];
// Remove unsupported properties
delete manifest.content_security_policy.sandbox;
delete manifest.sandbox;
delete manifest.applications;
manifest.permissions = manifest.permissions.filter((permission) => permission !== "offscreen");
if (browser === "safari") {
delete manifest.sidebar_action;
delete manifest.commands._execute_sidebar_action;
delete manifest.optional_permissions;
manifest.permissions.push("nativeMessaging");
}
if (browser === "firefox") {
delete manifest.storage;
manifest.optional_permissions = manifest.optional_permissions.filter(
(permission) => permission !== "privacy",
);
}
return JSON.stringify(manifest, null, 2);
}
console.log(`Building Manifest Version ${manifestVersion} app`);
@@ -133,7 +179,11 @@ const plugins = [
new CopyWebpackPlugin({
patterns: [
manifestVersion == 3
? { from: "./src/manifest.v3.json", to: "manifest.json" }
? {
from: "./src/manifest.v3.json",
to: "manifest.json",
transform: (content) => modifyManifestV3(content),
}
: "./src/manifest.json",
{ from: "./src/managed_schema.json", to: "managed_schema.json" },
{ from: "./src/_locales", to: "_locales" },
@@ -362,6 +412,20 @@ if (manifestVersion == 2) {
plugins: [...requiredPlugins],
};
// Safari's desktop build process requires a background.html and vendor.js file to exist
// within the root of the extension. This is a workaround to allow us to build Safari
// for manifest v2 and v3 without modifying the desktop project structure.
if (browser === "safari") {
backgroundConfig.plugins.push(
new CopyWebpackPlugin({
patterns: [
{ from: "./src/safari/mv3/fake-background.html", to: "background.html" },
{ from: "./src/safari/mv3/fake-vendor.js", to: "vendor.js" },
],
}),
);
}
configs.push(mainConfig);
configs.push(backgroundConfig);
}