Skip to content
Closed
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
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

### [1.3.2](https://github.com/dessant/buster/compare/v1.3.1...v1.3.2) (2022-09-01)


### Bug Fixes

* set correct tabindex for extension button ([d68ce72](https://github.com/dessant/buster/commit/d68ce72e8d3664939cac5ce677c2dfd988ea732a))
* update client app navigation ([3fae62e](https://github.com/dessant/buster/commit/3fae62ee4adde746ab46299732df7535c81592bd)), closes [#360](https://github.com/dessant/buster/issues/360)

### [1.3.1](https://github.com/dessant/buster/compare/v1.3.0...v1.3.1) (2021-11-02)


Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ by giving us easy access to solutions already utilized by automated systems.
## Screenshots

<p>
<img width="414" src="https://i.imgur.com/hTqeN4z.png">
<img width="414" src="https://i.imgur.com/o0qqDd5.png">
<img width="380" src="https://i.imgur.com/hTqeN4z.png">
<img width="380" src="https://i.imgur.com/o0qqDd5.png">
</p>

## License

Copyright (c) 2018-2021 Armin Sebastian
Copyright (c) 2018-2022 Armin Sebastian

This software is released under the terms of the GNU General Public License v3.0.
See the [LICENSE](LICENSE) file for further information.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "buster",
"version": "1.3.1",
"version": "1.3.2",
"author": "Armin Sebastian",
"repository": "https://github.com/dessant/buster",
"license": "GPL-3.0-only",
Expand Down
49 changes: 45 additions & 4 deletions src/background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,10 +546,51 @@ async function onMessage(request, sender) {
await resetCaptcha(sender.tab.id, sender.frameId, request.challengeUrl);
} else if (request.id === 'getFramePos') {
return getFramePos(sender.tab.id, sender.frameId, request.frameIndex);
} else if (request.id === 'getTabZoom') {
return browser.tabs.getZoom(sender.tab.id);
} else if (request.id === 'getBackgroundScriptScale') {
return window.devicePixelRatio;
} else if (request.id === 'getOsScale') {
let zoom = await browser.tabs.getZoom(sender.tab.id);

const [[scale, windowWidth]] = await browser.tabs.executeScript(
sender.tab.id,
{
code: `[window.devicePixelRatio, window.innerWidth];`,
runAt: 'document_start'
}
);

if (targetEnv === 'firefox') {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1787649

function getImageElement(url) {
return new Promise(resolve => {
const img = new Image();
img.onload = () => {
resolve(img);
};
img.onerror = () => {
resolve();
};
img.onabort = () => {
resolve();
};
img.src = url;
});
}

const screenshotWidth = (
await getImageElement(
await browser.tabs.captureVisibleTab({
format: 'jpeg',
quality: 10
})
)
).naturalWidth;

if (Math.abs(screenshotWidth / windowWidth - scale * zoom) < 0.005) {
zoom = 1;
}
}

return scale / zoom;
} else if (request.id === 'startClientApp') {
nativePort = browser.runtime.connectNative('org.buster.client');
} else if (request.id === 'stopClientApp') {
Expand Down
2 changes: 1 addition & 1 deletion src/content/initReset.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ function initReset(challengeUrl) {
new CustomEvent('___resetCaptcha', {detail: challengeUrl})
);
};
script.src = chrome.extension.getURL('/src/content/reset.js');
script.src = chrome.runtime.getURL('/src/content/reset.js');
document.documentElement.appendChild(script);
}

Expand Down
2 changes: 1 addition & 1 deletion src/content/setup.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function setup() {
const url = new URL(chrome.extension.getURL('/src/setup/index.html'));
const url = new URL(chrome.runtime.getURL('/src/setup/index.html'));
url.searchParams.set(
'session',
new URL(window.location.href).searchParams.get('session')
Expand Down
77 changes: 48 additions & 29 deletions src/solve/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@ import browser from 'webextension-polyfill';

import storage from 'storage/storage';
import {meanSleep, pingClientApp} from 'utils/app';
import {getText, waitForElement, getRandomFloat, sleep} from 'utils/common';
import {
getText,
waitForElement,
getRandomFloat,
sleep,
getBrowser
} from 'utils/common';
import {targetEnv, clientAppVersion} from 'utils/config';

let solverWorking = false;
Expand Down Expand Up @@ -51,13 +57,20 @@ function syncUI() {
helpButton.remove();

const helpButtonHolder = document.querySelector('.help-button-holder');
const shadow = helpButtonHolder.attachShadow({mode: 'closed'});
helpButtonHolder.tabIndex = document.querySelector('audio#audio-source')
? 0
: 2;

const shadow = helpButtonHolder.attachShadow({
mode: 'closed',
delegatesFocus: true
});

const link = document.createElement('link');
link.setAttribute('rel', 'stylesheet');
link.setAttribute(
'href',
browser.extension.getURL('/src/solve/solver-button.css')
browser.runtime.getURL('/src/solve/solver-button.css')
);
shadow.appendChild(link);

Expand Down Expand Up @@ -133,8 +146,8 @@ async function tapEnter(node, {navigateForward = true} = {}) {
await messageClientApp({command: 'tapKey', data: 'enter'});
}

async function clickElement(node, browserBorder) {
const targetPos = await getClickPos(node, browserBorder);
async function clickElement(node, browserBorder, osScale) {
const targetPos = await getClickPos(node, browserBorder, osScale);
await messageClientApp({command: 'moveMouse', ...targetPos});
await meanSleep(100);
await messageClientApp({command: 'clickMouse'});
Expand All @@ -154,31 +167,31 @@ async function messageClientApp(message) {
}

async function getOsScale() {
// The background script devicePixelRatio is not affected by the default
// zoom level in Firefox, while the content script devicePixelRatio
// is affected, unless only text is zoomed.
if (targetEnv === 'firefox') {
return browser.runtime.sendMessage({id: 'getBackgroundScriptScale'});
}

const zoom = await browser.runtime.sendMessage({id: 'getTabZoom'});

return window.devicePixelRatio / zoom;
return browser.runtime.sendMessage({id: 'getOsScale'});
}

async function getBrowserBorder(clickEvent) {
async function getBrowserBorder(clickEvent, osScale) {
const framePos = await getFrameClientPos();
const scale = window.devicePixelRatio;
const osScale = await getOsScale();

let evScreenPropScale = osScale;
if (
targetEnv === 'firefox' &&
parseInt((await getBrowser()).version.split('.')[0], 10) >= 99
) {
// https://bugzilla.mozilla.org/show_bug.cgi?id=1753836

evScreenPropScale = scale;
}

return {
left:
clickEvent.screenX * osScale -
clickEvent.screenX * evScreenPropScale -
clickEvent.clientX * scale -
framePos.x -
window.screenX * scale,
top:
clickEvent.screenY * osScale -
clickEvent.screenY * evScreenPropScale -
clickEvent.clientY * scale -
framePos.y -
window.screenY * scale
Expand All @@ -202,7 +215,7 @@ async function getFrameClientPos() {
return {x: 0, y: 0};
}

async function getElementScreenRect(node, browserBorder) {
async function getElementScreenRect(node, browserBorder, osScale) {
let {left: x, top: y, width, height} = node.getBoundingClientRect();

const data = await getFrameClientPos();
Expand All @@ -218,7 +231,6 @@ async function getElementScreenRect(node, browserBorder) {

const {os} = await browser.runtime.sendMessage({id: 'getPlatform'});
if (['windows', 'macos'].includes(os)) {
const osScale = await getOsScale();
x /= osScale;
y /= osScale;
width /= osScale;
Expand All @@ -228,8 +240,12 @@ async function getElementScreenRect(node, browserBorder) {
return {x, y, width, height};
}

async function getClickPos(node, browserBorder) {
let {x, y, width, height} = await getElementScreenRect(node, browserBorder);
async function getClickPos(node, browserBorder, osScale) {
let {x, y, width, height} = await getElementScreenRect(
node,
browserBorder,
osScale
);

return {
x: Math.round(x + width * getRandomFloat(0.4, 0.6)),
Expand All @@ -248,10 +264,12 @@ async function solve(simulateUserInput, clickEvent) {
);

let browserBorder;
let osScale;
let useMouse = true;
if (simulateUserInput) {
if (!navigateWithKeyboard && (clickEvent.clientX || clickEvent.clientY)) {
browserBorder = await getBrowserBorder(clickEvent);
osScale = await getOsScale();
browserBorder = await getBrowserBorder(clickEvent, osScale);
} else {
useMouse = false;
}
Expand All @@ -263,9 +281,10 @@ async function solve(simulateUserInput, clickEvent) {
const audioButton = document.querySelector('#recaptcha-audio-button');
if (simulateUserInput) {
if (useMouse) {
await clickElement(audioButton, browserBorder);
await clickElement(audioButton, browserBorder, osScale);
} else {
await tapEnter(audioButton, {navigateForward: false});
audioButton.focus();
await tapEnter(audioButton);
}
} else {
dispatchEnter(audioButton);
Expand Down Expand Up @@ -325,7 +344,7 @@ async function solve(simulateUserInput, clickEvent) {
'.rc-audiochallenge-play-button > button'
);
if (useMouse) {
await clickElement(playButton, browserBorder);
await clickElement(playButton, browserBorder, osScale);
} else {
await tapEnter(playButton);
}
Expand All @@ -347,7 +366,7 @@ async function solve(simulateUserInput, clickEvent) {
const input = document.querySelector('#audio-response');
if (simulateUserInput) {
if (useMouse) {
await clickElement(input, browserBorder);
await clickElement(input, browserBorder, osScale);
} else {
await navigateToElement(input);
}
Expand All @@ -361,7 +380,7 @@ async function solve(simulateUserInput, clickEvent) {
const submitButton = document.querySelector('#recaptcha-verify-button');
if (simulateUserInput) {
if (useMouse) {
await clickElement(submitButton, browserBorder);
await clickElement(submitButton, browserBorder, osScale);
} else {
await tapEnter(submitButton);
}
Expand Down
4 changes: 4 additions & 0 deletions src/solve/solver-button.css
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
outline: none;
}

#solver-button:focus-visible {
background-color: rgba(216, 216, 216, 0.8);
}

#solver-button.working {
background-image: url('data:image/svg+xml,%3Csvg%20width%3D%2244%22%20height%3D%2244%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20stroke%3D%22%23727272%22%3E%3Cg%20fill%3D%22none%22%20fill-rule%3D%22evenodd%22%20stroke-width%3D%225%22%3E%3Ccircle%20cx%3D%2222%22%20cy%3D%2222%22%20r%3D%221%22%3E%3Canimate%20attributeName%3D%22r%22%20begin%3D%220s%22%20dur%3D%221.8s%22%20values%3D%221%3B%2020%22%20calcMode%3D%22spline%22%20keyTimes%3D%220%3B%201%22%20keySplines%3D%220.165%2C%200.84%2C%200.44%2C%201%22%20repeatCount%3D%22indefinite%22%2F%3E%3Canimate%20attributeName%3D%22stroke-opacity%22%20begin%3D%220s%22%20dur%3D%221.8s%22%20values%3D%221%3B%200%22%20calcMode%3D%22spline%22%20keyTimes%3D%220%3B%201%22%20keySplines%3D%220.3%2C%200.61%2C%200.355%2C%201%22%20repeatCount%3D%22indefinite%22%2F%3E%3C%2Fcircle%3E%3Ccircle%20cx%3D%2222%22%20cy%3D%2222%22%20r%3D%221%22%3E%3Canimate%20attributeName%3D%22r%22%20begin%3D%22-0.9s%22%20dur%3D%221.8s%22%20values%3D%221%3B%2020%22%20calcMode%3D%22spline%22%20keyTimes%3D%220%3B%201%22%20keySplines%3D%220.165%2C%200.84%2C%200.44%2C%201%22%20repeatCount%3D%22indefinite%22%2F%3E%3Canimate%20attributeName%3D%22stroke-opacity%22%20begin%3D%22-0.9s%22%20dur%3D%221.8s%22%20values%3D%221%3B%200%22%20calcMode%3D%22spline%22%20keyTimes%3D%220%3B%201%22%20keySplines%3D%220.3%2C%200.61%2C%200.355%2C%201%22%20repeatCount%3D%22indefinite%22%2F%3E%3C%2Fcircle%3E%3C%2Fg%3E%3C%2Fsvg%3E') !important;
opacity: 1;
Expand Down
2 changes: 1 addition & 1 deletion src/utils/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ function getOptionLabels(data, scope = 'optionValue') {

async function showContributePage(action = false) {
const activeTab = await getActiveTab();
let url = browser.extension.getURL('/src/contribute/index.html');
let url = browser.runtime.getURL('/src/contribute/index.html');
if (action) {
url = `${url}?action=${action}`;
}
Expand Down