Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add surrogate-based replacement placeholders for Rumble and Google reCAPTCHA widgets #2805

Merged
merged 18 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions src/data/socialwidgets.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
"Google reCAPTCHA": {
"domains": [
"google.com",
"www.google.com"
"www.google.com",
"recaptcha.net",
"www.recaptcha.net"
],
"buttonSelectors": [
"div.g-recaptcha",
Expand All @@ -156,13 +158,17 @@
"scriptSelectors": [
"script[src^='//google.com/recaptcha/api.js']",
"script[src^='https://google.com/recaptcha/api.js']",
"script[src^='https://www.google.com/recaptcha/api.js']"
"script[src^='https://www.google.com/recaptcha/api.js']",
"script[src^='//recaptcha.net/recaptcha/api.js']",
"script[src^='https://recaptcha.net/recaptcha/api.js']",
"script[src^='https://www.recaptcha.net/recaptcha/api.js']"
],
"fallbackScriptUrl": "//google.com/recaptcha/api.js",
"replacementButton": {
"unblockDomains": [
"google.com",
"www.google.com"
"www.google.com",
"recaptcha.net",
"www.recaptcha.net"
],
"type": 4
}
Expand Down Expand Up @@ -203,6 +209,18 @@
"type": 0
}
},
"Rumble Video Player": {
"domain": "rumble.com",
"buttonSelectors": [
"iframe[src^='https://rumble.com/embed/']"
],
"replacementButton": {
"unblockDomains": [
"rumble.com"
],
"type": 3
}
},
"SoundCloud": {
"domain": "w.soundcloud.com",
"buttonSelectors": [
Expand Down
41 changes: 41 additions & 0 deletions src/data/surrogates.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
require.scopes.surrogatedb = (function () {

const MATCH_SUFFIX = 'suffix',
MATCH_PREFIX = 'prefix',
MATCH_PREFIX_WITH_PARAMS = 'prefix_params',
MATCH_ANY = 'any';

/**
Expand Down Expand Up @@ -86,6 +88,38 @@ const hostnames = {
'/apstag.js',
]
},
'rumble.com': {
match: MATCH_PREFIX,
tokens: [
'/embedJS/',
],
widgetName: "Rumble Video Player"
},
'www.google.com': {
match: MATCH_PREFIX_WITH_PARAMS,
params: {
onload: true,
//render: "explicit",
render: true,
},
tokens: [
'/recaptcha/api.js',
'/recaptcha/enterprise.js',
],
widgetName: "Google reCAPTCHA"
},
'www.recaptcha.net': {
match: MATCH_PREFIX_WITH_PARAMS,
params: {
onload: true,
render: true,
},
tokens: [
'/recaptcha/api.js',
'/recaptcha/enterprise.js',
],
widgetName: "Google reCAPTCHA"
},
};

/**
Expand Down Expand Up @@ -121,6 +155,11 @@ const surrogates = {

'/apstag.js': 'amazon_apstag.js',

'/embedJS/': 'rumble_embedjs.js',

'/recaptcha/api.js': 'grecaptcha.js',
'/recaptcha/enterprise.js': 'grecaptcha_enterprise.js',

'noopjs': 'noop.js'
};

Expand All @@ -132,6 +171,8 @@ Object.keys(surrogates).forEach(key => {

const exports = {
MATCH_ANY,
MATCH_PREFIX,
MATCH_PREFIX_WITH_PARAMS,
MATCH_SUFFIX,
hostnames,
surrogates,
Expand Down
31 changes: 31 additions & 0 deletions src/data/web_accessible_resources/grecaptcha.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function () {

let script_src = document.currentScript.src;

window.grecaptcha = {
render: function (container) {
if (Object.prototype.toString.call(container) != "[object String]") {
if (!container.id) {
container.id = "grecaptcha-" + Math.random().toString().replace(".", "");
}
container = container.id;
}
document.dispatchEvent(new CustomEvent("pbSurrogateMessage", {
detail: {
type: "widgetFromSurrogate",
name: "Google reCAPTCHA",
widgetData: {
domId: container,
scriptUrl: script_src
}
}
}));
}
};

let onload = (new URL(script_src)).searchParams.get('onload');
if (onload && onload in window) {
window[onload]();
}

}());
37 changes: 37 additions & 0 deletions src/data/web_accessible_resources/grecaptcha_enterprise.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function () {

let script_src = document.currentScript.src;

window.grecaptcha = {};

window.grecaptcha.enterprise = {
ready: function (cb) {
cb();
},
render: function (container) {
if (Object.prototype.toString.call(container) != "[object String]") {
if (!container.id) {
container.id = "grecaptcha-" + Math.random().toString().replace(".", "");
}
container = container.id;
}
document.dispatchEvent(new CustomEvent("pbSurrogateMessage", {
detail: {
type: "widgetFromSurrogate",
name: "Google reCAPTCHA",
widgetData: {
domId: container,
scriptUrl: script_src
}
}
}));
},
execute: function () {}
};

let onload = (new URL(script_src)).searchParams.get('onload');
if (onload && onload in window) {
window[onload]();
}

}());
38 changes: 38 additions & 0 deletions src/data/web_accessible_resources/rumble_embedjs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
(function () {
if ("Rumble" in window && "_" in window.Rumble) {
for (let args of window.Rumble._) {
args = [].slice.apply(args);

let cmd = args[0],
conf = args[1],
script_src = document.currentScript.src,
idx = script_src.indexOf("/embedJS/"),
pub_code;

if (idx != -1) {
script_src = script_src.slice(idx + "/embedJS/".length);
idx = script_src.indexOf("/");
if (idx != -1) {
script_src = script_src.slice(0, idx);
idx = script_src.indexOf(".");
if (idx != -1) {
pub_code = script_src.slice(0, idx);
}
}
}

if (pub_code && cmd == "play" && "div" in conf && "video" in conf) {
document.dispatchEvent(new CustomEvent("pbSurrogateMessage", {
detail: {
type: "widgetFromSurrogate",
name: "Rumble Video Player",
widgetData: {
pubCode: pub_code,
args
}
}
}));
}
}
}
}());
2 changes: 2 additions & 0 deletions src/js/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ Badger.prototype = {
<frame_id>: {
url: {String}
host: {String}
widgetReplacementReady: {Boolean}
widgetQueue: {Array} widget objects
warAccessTokens: {
<extension_resource_URL>: {String} access token
...
Expand Down
Loading