fix: add button to existing challenge widgets after installation in Chrome

pull/219/head
dessant 4 years ago
parent fbbdc5bce0
commit 1b9af9e93c

@ -21,6 +21,7 @@ import {
sliceAudio
} from 'utils/common';
import {
recaptchaChallengeUrlRx,
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes,
captchaMicrosoftSpeechApiLangCodes,
@ -509,6 +510,55 @@ function addMessageListener() {
browser.runtime.onMessage.addListener(onMessage);
}
async function onInstall(details) {
if (
['chrome', 'edge', 'opera'].includes(targetEnv) &&
['install', 'update'].includes(details.reason)
) {
const tabs = await browser.tabs.query({
url: ['http://*/*', 'https://*/*'],
windowType: 'normal'
});
for (const tab of tabs) {
const tabId = tab.id;
const frames = await browser.webNavigation.getAllFrames({tabId});
for (const frame of frames) {
const frameId = frame.frameId;
if (frameId && recaptchaChallengeUrlRx.test(frame.url)) {
await browser.tabs.insertCSS(tabId, {
frameId,
runAt: 'document_idle',
file: 'src/solve/style.css'
});
await browser.tabs.executeScript(tabId, {
frameId,
runAt: 'document_idle',
file: '/src/manifest.js'
});
await browser.tabs.executeScript(tabId, {
frameId,
runAt: 'document_idle',
file: '/src/solve/script.js'
});
}
}
}
const setupTabs = await browser.tabs.query({
url: 'http://127.0.0.1/buster/setup?session=*',
windowType: 'normal'
});
for (const tab of setupTabs) {
await browser.tabs.reload(tab.id);
}
}
}
async function onLoad() {
await initStorage('sync');
await setChallengeLocale();
@ -516,4 +566,6 @@ async function onLoad() {
addMessageListener();
}
browser.runtime.onInstalled.addListener(onInstall);
document.addEventListener('DOMContentLoaded', onLoad);

@ -19,6 +19,8 @@ const clientAppPlatforms = [
'macos/amd64'
];
const recaptchaChallengeUrlRx = /^https:\/\/www\.google\.com\/recaptcha\/api2\/bframe.*/;
// https://developers.google.com/recaptcha/docs/language
// https://cloud.google.com/speech-to-text/docs/languages
const captchaGoogleSpeechApiLangCodes = {
@ -371,6 +373,7 @@ const microsoftSpeechApiUrls = {
export {
optionKeys,
clientAppPlatforms,
recaptchaChallengeUrlRx,
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes,
captchaMicrosoftSpeechApiLangCodes,

Loading…
Cancel
Save