forked from brave/browser-laptop
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Resolves brave#14351 Auditors: Test Plan:
- Loading branch information
Showing
3 changed files
with
81 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
diff --git a/app/extensions/brave/content/scripts/metaScraper.js b/app/extensions/brave/content/scripts/metaScraper.js | ||
index e8855b2ff..5dc2316d2 100644 | ||
--- a/app/extensions/brave/content/scripts/metaScraper.js | ||
+++ b/app/extensions/brave/content/scripts/metaScraper.js | ||
@@ -98,5 +98,16 @@ const metaScraperRules = { | ||
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="author"]')))), | ||
requestHandlerApi.strict(wrap(html => requestHandlerApi.getValue(html.querySelectorAll('[class*="byline"]')))) | ||
] | ||
+ }, | ||
+ | ||
+ getUrlRules: () => { | ||
+ const wrap = rule => ({htmlDom, url}) => { | ||
+ const value = rule(htmlDom) | ||
+ return requestHandlerApi.isUrl(value, {relative: false}) && value | ||
+ } | ||
+ | ||
+ return [ | ||
+ wrap(html => requestHandlerApi.getHref(html.querySelector('link[rel="canonical"]'))) | ||
+ ] | ||
} | ||
} | ||
diff --git a/app/extensions/brave/content/scripts/requestHandler.js b/app/extensions/brave/content/scripts/requestHandler.js | ||
index 7cf875893..518680c77 100644 | ||
--- a/app/extensions/brave/content/scripts/requestHandler.js | ||
+++ b/app/extensions/brave/content/scripts/requestHandler.js | ||
@@ -51,13 +51,15 @@ const requestHandlerApi = { | ||
const result = { | ||
image: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getImageRules() }), | ||
title: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getTitleRules() }), | ||
- author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() }) | ||
+ author: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getAuthorRules() }), | ||
+ url: await requestHandlerApi.getData({ htmlDom, finalUrl, conditions: metaScraperRules.getUrlRules() }) | ||
} | ||
|
||
ipc.send(`got-publisher-info-${url}`, { | ||
error: null, | ||
body: { | ||
- url: finalUrl, | ||
+ finalUrl: finalUrl, | ||
+ url: sanitizeHtml(result.url) || finalUrl, | ||
title: sanitizeHtml(result.title) || '', | ||
image: sanitizeHtml(result.image) || '', | ||
author: sanitizeHtml(result.author) || '' | ||
@@ -116,6 +118,14 @@ const requestHandlerApi = { | ||
return selector.src | ||
}, | ||
|
||
+ getHref: (selector) => { | ||
+ if (!selector) { | ||
+ return null | ||
+ } | ||
+ | ||
+ return selector.href | ||
+ }, | ||
+ | ||
urlTest: (url, opts) => { | ||
let relative | ||
if (opts == null) { |