mirror of
https://github.com/jiahaog/Nativefier
synced 2024-06-21 07:06:35 +02:00
7a08a2d676
* Catch promise errors better * Move subFunctions to bottom of createNewWindow * Use parents when creating child BrowserWindow instances * Some about:blank pages have an anchor (for some reason) * Inject browserWindowOptions better * Interim refactor to MainWindow object * Split up the window functions/helpers/events some * Further separate out window functions + tests * Add a mock for unit testing functions that access electron * Add unit tests for onWillPreventUnload * Improve windowEvents tests * Add the first test for windowHelpers * Move WebRequest event handling to node * insertCSS completely under test * clearAppData completely under test * Fix contextMenu require bug * More tests + fixes * Fix + add to createNewTab tests * Convert createMainWindow back to func + work out gremlins * Move setupWindow away from main since its shared * Make sure contextMenu is handling promises * Fix issues with fullscreen not working + menu refactor * Run jest against app/dist so that we can hit app unit tests as well * Requested PR changes * Add strict typing; tests currently failing * Fix failing unit tests * Add some more eslint warnings and fixes * More eslint fixes * Strict typing on (still issues with the lib dir) * Fix the package.json import/require * Fix some funky test errors * Warn -> Error for eslint rules * @ts-ignore -> @ts-expect-error * Add back the ext code I removed
21 lines
707 B
TypeScript
21 lines
707 B
TypeScript
import axios from 'axios';
|
|
import * as log from 'loglevel';
|
|
|
|
const USER_AGENT =
|
|
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2227.1 Safari/537.36';
|
|
|
|
export async function inferTitle(url: string): Promise<string> {
|
|
const { data } = await axios.get<string>(url, {
|
|
headers: {
|
|
// Fake user agent for pages like http://messenger.com
|
|
'User-Agent': USER_AGENT,
|
|
},
|
|
});
|
|
log.debug(`Fetched ${(data.length / 1024).toFixed(1)} kb page at`, url);
|
|
const inferredTitle =
|
|
/<\s*title.*?>(?<title>.+?)<\s*\/title\s*?>/i.exec(data)?.groups?.title ??
|
|
'Webapp';
|
|
log.debug('Inferred title:', inferredTitle);
|
|
return inferredTitle;
|
|
}
|