diff --git a/src/index.js b/src/index.js index 3c5be37..5556f03 100644 --- a/src/index.js +++ b/src/index.js @@ -1,7 +1,7 @@ import { join, dirname, delimiter, sep, isAbsolute } from 'path'; import { access, readdir } from 'fs/promises'; import { fileURLToPath } from 'url'; -import { log } from './lib/logger.js'; +import { log, dangerousAPI } from './lib/logger.js'; import Chromium from './browser/chromium.js'; import Firefox from './browser/firefox.js'; @@ -226,11 +226,17 @@ const startBrowser = async (url, { allowHTTP = false, allowRedirects = 'same-ori 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 = {}) => { 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.`); + checkForDangerousOptions(opts); log('starting browser...'); const Browser = await startBrowser(url, opts); diff --git a/src/lib/logger.js b/src/lib/logger.js index ccc56ad..221d032 100644 --- a/src/lib/logger.js +++ b/src/lib/logger.js @@ -1,3 +1,5 @@ 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); \ No newline at end of file +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`)}`); \ No newline at end of file