2
2
mirror of https://github.com/Llewellynvdm/nativefier.git synced 2024-11-11 15:51:06 +00:00

(Attempt to) get rid of deprecated app dep wurl

This one may be problematic, as it used to do TLD stuff:
https://github.com/websanova/node-url/blob/7982a613bc/wurl.js#L4

So, the new WHATWG-URL-based implementation will consider
`asana.com` to be "external" to `app.asana.com`, contrarily to before.
Given the nature of Nativefier, I think it's actually what to expect,
that in this case your "out of the app", and in e.g. asana landing's page,
which you'd expect to see in your browser.

Let's see if users disagree with that.
This commit is contained in:
Ronan Jouchet 2021-02-25 18:48:00 -05:00
parent fe79fd622d
commit 6b266b7815
2 changed files with 14 additions and 6 deletions

View File

@ -16,8 +16,7 @@
"electron-dl": "^3.1.0", "electron-dl": "^3.1.0",
"electron-squirrel-startup": "^1.0.0", "electron-squirrel-startup": "^1.0.0",
"electron-window-state": "^5.0.3", "electron-window-state": "^5.0.3",
"source-map-support": "^0.5.19", "source-map-support": "^0.5.19"
"wurl": "^2.5.4"
}, },
"devDependencies": { "devDependencies": {
"electron": "^11.3.0" "electron": "^11.3.0"

View File

@ -3,7 +3,6 @@ import * as os from 'os';
import * as path from 'path'; import * as path from 'path';
import { BrowserWindow } from 'electron'; import { BrowserWindow } from 'electron';
import wurl from 'wurl';
const INJECT_CSS_PATH = path.join(__dirname, '..', 'inject/inject.css'); const INJECT_CSS_PATH = path.join(__dirname, '..', 'inject/inject.css');
@ -33,9 +32,19 @@ export function linkIsInternal(
return regex.test(newUrl); return regex.test(newUrl);
} }
const currentDomain = wurl('domain', currentUrl); try {
const newDomain = wurl('domain', newUrl); const currentDomain = new URL(currentUrl).hostname;
return currentDomain === newDomain; const newDomain = new URL(newUrl).hostname;
return currentDomain === newDomain;
} catch (err) {
console.warn(
'Failed to parse domains as determining if link is internal. From:',
currentUrl,
'To:',
newUrl,
);
return false;
}
} }
export function shouldInjectCss(): boolean { export function shouldInjectCss(): boolean {