Skip to content

Commit

Permalink
fix: add button to existing challenge widgets after installation in C…
Browse files Browse the repository at this point in the history
…hrome
  • Loading branch information
dessant committed May 28, 2020
1 parent fbbdc5b commit 1b9af9e
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
52 changes: 52 additions & 0 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
sliceAudio
} from 'utils/common';
import {
recaptchaChallengeUrlRx,
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes,
captchaMicrosoftSpeechApiLangCodes,
Expand Down Expand Up @@ -509,11 +510,62 @@ 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();
addStorageListener();
addMessageListener();
}

browser.runtime.onInstalled.addListener(onInstall);

document.addEventListener('DOMContentLoaded', onLoad);
3 changes: 3 additions & 0 deletions src/utils/data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down Expand Up @@ -371,6 +373,7 @@ const microsoftSpeechApiUrls = {
export {
optionKeys,
clientAppPlatforms,
recaptchaChallengeUrlRx,
captchaGoogleSpeechApiLangCodes,
captchaIbmSpeechApiLangCodes,
captchaMicrosoftSpeechApiLangCodes,
Expand Down

0 comments on commit 1b9af9e

Please sign in to comment.