extensions: initial add
This commit is contained in:
parent
e36cdc9db3
commit
a32295870d
@ -7,13 +7,15 @@ const presets = { // Presets from OpenAsar
|
||||
'memory': '--in-process-gpu --js-flags="--lite-mode --optimize_for_size --wasm_opt --wasm_lazy_compilation --wasm_lazy_validation --always_compact" --renderer-process-limit=2 --enable-features=QuickIntensiveWakeUpThrottlingAfterLoading' // Less (?) memory usage
|
||||
};
|
||||
|
||||
export default async ({ browserPath, dataPath }, { url, windowSize, allowHTTP }, extra) => {
|
||||
export default async ({ browserPath, dataPath }, { url, windowSize, allowHTTP, extensions }, extra) => {
|
||||
console.log(extensions);
|
||||
|
||||
return await StartBrowser(browserPath, [
|
||||
`--app=${url}`,
|
||||
`--remote-debugging-pipe`,
|
||||
`--user-data-dir=${dataPath}`,
|
||||
windowSize ? `--window-size=${windowSize.join(',')}` : '',
|
||||
![true, 'mixed'].includes(allowHTTP) ? `--enable-strict-mixed-content-checking` : '--allow-running-insecure-content',
|
||||
...`--new-window --no-first-run --no-default-browser-check --disable-component-extensions-with-background-pages --disable-extensions --disable-default-apps --disable-breakpad --disable-crashpad --disable-background-networking --disable-domain-reliability --disable-component-update --disable-sync --disable-features=AutofillServerCommunication --in-process-gpu ${presets.perf}`.split(' ')
|
||||
Array.isArray(extensions) && extensions.length > 0 ? `--load-extension=${(await Promise.all(extensions)).flat().join(',')}` : '',
|
||||
...`--new-window --no-first-run --no-default-browser-check --disable-component-extensions-with-background-pages --disable-default-apps --disable-breakpad --disable-crashpad --disable-background-networking --disable-domain-reliability --disable-component-update --disable-sync --disable-features=AutofillServerCommunication --in-process-gpu ${presets.perf}`.split(' ')
|
||||
], 'stdio', extra);
|
||||
};
|
@ -1,10 +1,11 @@
|
||||
import { mkdir, writeFile } from 'fs/promises';
|
||||
import { join } from 'path';
|
||||
import { mkdir, writeFile, copyFile, access } from 'fs/promises';
|
||||
import { join, basename } from 'path';
|
||||
|
||||
import StartBrowser from '../launcher/start.js';
|
||||
|
||||
const exists = path => access(path).then(() => true).catch(() => false);
|
||||
|
||||
export default async ({ browserPath, dataPath }, { url, windowSize, allowHTTP }, extra) => {
|
||||
export default async ({ browserPath, dataPath }, { url, windowSize, allowHTTP, extensions }, extra) => {
|
||||
await mkdir(dataPath, { recursive: true });
|
||||
await writeFile(join(dataPath, 'user.js'), `
|
||||
user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true);
|
||||
@ -31,7 +32,7 @@ user_pref('security.mixed_content.upgrade_display_content', true);
|
||||
/* user_pref('privacy.window.maxInnerWidth', ${windowSize[0]});
|
||||
user_pref('privacy.window.maxInnerHeight', ${windowSize[1]}); */
|
||||
|
||||
await mkdir(join(dataPath, 'chrome'), { recursive: true });
|
||||
await mkdir(join(dataPath, 'chrome'));
|
||||
await writeFile(join(dataPath, 'chrome', 'userChrome.css'), `
|
||||
.titlebar-spacer, #firefox-view-button, #alltabs-button, #tabbrowser-arrowscrollbox-periphery, .tab-close-button {
|
||||
display: none;
|
||||
@ -78,6 +79,12 @@ html:not([tabsintitlebar="true"]) .tab-icon-image {
|
||||
}
|
||||
`);
|
||||
|
||||
await mkdir(join(dataPath, 'extensions'));
|
||||
for (const ext of (await Promise.all(extensions)).flat()) {
|
||||
const installPath = join(dataPath, 'extensions', basename(ext));
|
||||
if (!await exists(installPath)) await copyFile(ext, installPath);
|
||||
}
|
||||
|
||||
return await StartBrowser(browserPath, [
|
||||
...(!windowSize ? [] : [ `-window-size`, windowSize.join(',') ]),
|
||||
`-profile`, dataPath,
|
||||
|
24
src/extensions.js
Normal file
24
src/extensions.js
Normal file
@ -0,0 +1,24 @@
|
||||
export const _extensions = {
|
||||
chromium: [],
|
||||
firefox: []
|
||||
};
|
||||
|
||||
const parseArgs = args => args.flatMap(x => typeof x === 'function' ? x() : x);
|
||||
|
||||
export const add = (..._args) => {
|
||||
const args = parseArgs(_args);
|
||||
|
||||
for (const ext of args) {
|
||||
if (ext.chromium) _extensions.chromium.push(ext.chromium);
|
||||
if (ext.firefox) _extensions.firefox.push(ext.firefox);
|
||||
}
|
||||
};
|
||||
|
||||
export const remove = (..._args) => {
|
||||
const args = parseArgs(_args);
|
||||
|
||||
for (const ext of args) {
|
||||
if (ext.chromium) _extensions.chromium.splice(_extensions.chromium.indexOf(ext.chromium), 1);
|
||||
if (ext.firefox) _extensions.firefox.splice(_extensions.firefox.indexOf(ext.firefox), 1);
|
||||
}
|
||||
};
|
10
src/index.js
10
src/index.js
@ -6,6 +6,7 @@ import { log } from './lib/logger.js';
|
||||
import Chromium from './browser/chromium.js';
|
||||
import Firefox from './browser/firefox.js';
|
||||
|
||||
import * as ExtensionsAPI from './extensions.js';
|
||||
import LocalHTTP from './lib/local/http.js';
|
||||
|
||||
process.versions.gluon = '0.13.0-alpha.0';
|
||||
@ -200,7 +201,8 @@ const startBrowser = async (url, { allowHTTP, windowSize, forceBrowser, forceEng
|
||||
}, {
|
||||
url: openingLocal ? localUrl : url,
|
||||
windowSize,
|
||||
allowHTTP
|
||||
allowHTTP,
|
||||
extensions: ExtensionsAPI._extensions[browserType]
|
||||
}, {
|
||||
browserName: browserFriendlyName,
|
||||
url: openingLocal ? basePath : url,
|
||||
@ -232,11 +234,15 @@ export const open = async (url, opts = {}) => {
|
||||
|
||||
Browser.page.eval(toRun);
|
||||
|
||||
await Browser.cdp.send(`Page.enable`);
|
||||
await Browser.cdp.send(`Page.addScriptToEvaluateOnNewDocument`, {
|
||||
source: toRun
|
||||
});
|
||||
}
|
||||
|
||||
return Browser;
|
||||
};
|
||||
|
||||
export const extensions = {
|
||||
add: ExtensionsAPI.add,
|
||||
remove: ExtensionsAPI.remove
|
||||
};
|
Loading…
x
Reference in New Issue
Block a user