diff --git a/app/cmdLine.js b/app/cmdLine.js index 734bc2b7613..48cab3556ac 100644 --- a/app/cmdLine.js +++ b/app/cmdLine.js @@ -43,19 +43,25 @@ const focusOrOpenWindow = function (url) { return true } +const isProtocolHandled = (protocol) => { + protocol = (protocol || '').split(':')[0] + return navigatableTypes.includes(protocol) || + electron.session.defaultSession.protocol.isNavigatorProtocolHandled(protocol) +} + // Checks an array of arguments if it can find a url const getUrlFromCommandLine = (argv) => { if (argv) { if (argv.length === 2 && !argv[1].startsWith('-')) { const parsedUrl = urlParse(argv[1]) - if (navigatableTypes.includes(parsedUrl.protocol)) { + if (isProtocolHandled(parsedUrl.protocol)) { return argv[1] } } const index = argv.indexOf('--') if (index !== -1 && index + 1 < argv.length && !argv[index + 1].startsWith('-')) { const parsedUrl = urlParse(argv[index + 1]) - if (navigatableTypes.includes(parsedUrl.protocol)) { + if (isProtocolHandled(parsedUrl.protocol)) { return argv[index + 1] } } @@ -68,7 +74,7 @@ if (!isDarwin) { const openUrl = getUrlFromCommandLine(process.argv) if (openUrl) { const parsedUrl = urlParse(openUrl) - if (navigatableTypes.includes(parsedUrl.protocol)) { + if (isProtocolHandled(parsedUrl.protocol)) { module.exports.newWindowURL = openUrl } } @@ -101,7 +107,7 @@ app.on('will-finish-launching', () => { app.on('open-url', (event, path) => { event.preventDefault() const parsedUrl = urlParse(path) - if (navigatableTypes.includes(parsedUrl.protocol)) { + if (isProtocolHandled(parsedUrl.protocol)) { if (!focusOrOpenWindow(path)) { module.exports.newWindowURL = path } diff --git a/js/lib/urlutil.js b/js/lib/urlutil.js index 91294b14f9a..0a9b57ffb4e 100644 --- a/js/lib/urlutil.js +++ b/js/lib/urlutil.js @@ -108,7 +108,7 @@ const UrlUtil = { // for cases, pure string const case3Reg = /[\?\.\/\s:]/ // for cases, data:uri, view-source:uri and about - const case4Reg = /^data|view-source|about|chrome-extension:.*/ + const case4Reg = /^data|view-source|mailto|about|chrome-extension:.*/ let str = input.trim() let scheme = this.getScheme(str) diff --git a/test/unit/lib/urlutilTest.js b/test/unit/lib/urlutilTest.js index f04ae424403..78d15a88bea 100644 --- a/test/unit/lib/urlutilTest.js +++ b/test/unit/lib/urlutilTest.js @@ -75,6 +75,9 @@ describe('urlutil', function () { it('returns false when input is chrome-extension', function () { assert.equal(UrlUtil.isNotURL('chrome-extension://fmfcbgogabcbclcofgocippekhfcmgfj/cast_sender.js'), false) }) + it('returns false when input is mailto', function () { + assert.equal(UrlUtil.isNotURL('mailto:brian@brave.com'), false) + }) describe('search query', function () { it('returns true when input starts with ?', function () { assert.equal(UrlUtil.isNotURL('?brave'), true)