logging: add dangerous warnings
This commit is contained in:
parent
fc15be85a0
commit
576d5e5518
@ -1,7 +1,7 @@
|
|||||||
import { join, dirname, delimiter, sep, isAbsolute } from 'path';
|
import { join, dirname, delimiter, sep, isAbsolute } from 'path';
|
||||||
import { access, readdir } from 'fs/promises';
|
import { access, readdir } from 'fs/promises';
|
||||||
import { fileURLToPath } from 'url';
|
import { fileURLToPath } from 'url';
|
||||||
import { log } from './lib/logger.js';
|
import { log, dangerousAPI } from './lib/logger.js';
|
||||||
|
|
||||||
import Chromium from './browser/chromium.js';
|
import Chromium from './browser/chromium.js';
|
||||||
import Firefox from './browser/firefox.js';
|
import Firefox from './browser/firefox.js';
|
||||||
@ -226,11 +226,17 @@ const startBrowser = async (url, { allowHTTP = false, allowRedirects = 'same-ori
|
|||||||
return Window;
|
return Window;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const checkForDangerousOptions = ({ allowHTTP, allowRedirects }) => {
|
||||||
|
if (allowHTTP === true) dangerousAPI('Gluon.open', 'allowHTTP', 'true');
|
||||||
|
if (allowRedirects === true) dangerousAPI('Gluon.open', 'allowRedirects', 'true');
|
||||||
|
};
|
||||||
|
|
||||||
export const open = async (url, opts = {}) => {
|
export const open = async (url, opts = {}) => {
|
||||||
const { onLoad, allowHTTP = false } = opts;
|
const { onLoad, allowHTTP = false } = opts;
|
||||||
|
|
||||||
if (allowHTTP !== true && url.startsWith('http://')) throw new Error(`HTTP URLs are blocked by default. Please use HTTPS, or if not possible, enable the 'allowHTTP' option.`);
|
if (allowHTTP !== true && url.startsWith('http://')) throw new Error(`HTTP URLs are blocked by default. Please use HTTPS, or if not possible, enable the 'allowHTTP' option.`);
|
||||||
|
|
||||||
|
checkForDangerousOptions(opts);
|
||||||
log('starting browser...');
|
log('starting browser...');
|
||||||
|
|
||||||
const Browser = await startBrowser(url, opts);
|
const Browser = await startBrowser(url, opts);
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
|
const rgb = (r, g, b, msg) => `\x1b[38;2;${r};${g};${b}m${msg}\x1b[0m`;
|
||||||
|
|
||||||
export const log = (...args) => console.log(`[${rgb(88, 101, 242, 'Gluon')}]`, ...args);
|
export const log = (...args) => console.log(`[${rgb(88, 101, 242, 'Gluon')}]`, ...args);
|
||||||
|
|
||||||
|
export const dangerousAPI = (func, option, value) => console.warn(`[${rgb(88, 101, 242, 'Gluon')}] ${rgb(250, 120, 20, `Using ${option}: ${value} (${func}) is dangerous`)}`);
|
Loading…
x
Reference in New Issue
Block a user