Skip to content

Commit

Permalink
Fix: Favicon url when a base element is present.
Browse files Browse the repository at this point in the history
Fix #2829
  • Loading branch information
sarvaje authored and antross committed Aug 23, 2019
1 parent f6b7cd9 commit c5a6c4a
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/connector-jsdom/src/connector.ts
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/connector-puppeteer/src/connector.ts
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions packages/connector-puppeteer/src/lib/get-favicon.ts
Expand Up @@ -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 });

Expand Down

0 comments on commit c5a6c4a

Please sign in to comment.