Skip to content
Permalink
Browse files

Fix: Favicon url when a base element is present.

Fix #2829
  • Loading branch information...
sarvaje authored and antross committed Aug 19, 2019
1 parent f6b7cd9 commit c5a6c4adc49298c62e80607b9098f1a2bdc8fde4
@@ -145,7 +145,7 @@ export default class JSDOMConnector implements IConnector {
const href = (element && element.getAttribute('href')) || '/favicon.ico';

try {
await this._resourceLoader!.fetch(new URL(href, this.finalHref).href, { element });
await this._resourceLoader!.fetch(this._document.resolveUrl(href), { element });
} catch (e) {
/* istanbul ignore next */
debug('Error loading ${href}', e);
@@ -321,7 +321,7 @@ export default class PuppeteerConnector implements IConnector {

if (this._options.headless) {
// TODO: Check if browser downloads favicon even if there's no content
await getFavicon(this._finalHref, this._dom, this.fetchContent.bind(this), this._engine);
await getFavicon(this._dom, this.fetchContent.bind(this), this._engine);
}

if (this._targetBody) {
@@ -13,13 +13,13 @@ const debug: debug.IDebugger = d(__filename);
* * uses the `src` attribute of `<link rel="icon">` if present.
* * uses `favicon.ico` and the final url after redirects.
*/
export const getFavicon = async (baseUrl: string, dom: HTMLDocument, fetchContent: Fetcher, engine: Engine) => {
export const getFavicon = async (dom: HTMLDocument, fetchContent: Fetcher, engine: Engine) => {
const element = (await dom.querySelectorAll('link[rel~="icon"]'))[0];
const href = (element && element.getAttribute('href')) || '/favicon.ico';

try {
debug(`resource ${href} to be fetched`);
const fullFaviconUrl = baseUrl + href.substr(1);
const fullFaviconUrl = dom.resolveUrl(href);

await engine.emitAsync('fetch::start', { resource: fullFaviconUrl });

0 comments on commit c5a6c4a

Please sign in to comment.
You can’t perform that action at this time.