diff --git a/src/background/main.js b/src/background/main.js index d08fdac..403cd2a 100644 --- a/src/background/main.js +++ b/src/background/main.js @@ -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); diff --git a/src/utils/data.js b/src/utils/data.js index 76ce5f4..a517e11 100755 --- a/src/utils/data.js +++ b/src/utils/data.js @@ -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,