diff --git a/injected/integration-test/broker-protection.spec.js b/injected/integration-test/broker-protection.spec.js index 74988f5921..ec86d25282 100644 --- a/injected/integration-test/broker-protection.spec.js +++ b/injected/integration-test/broker-protection.spec.js @@ -469,6 +469,46 @@ test.describe('Broker Protection communications', () => { await page.waitForURL((url) => url.hash === '#no', { timeout: 2000 }); }); + test('clicking selectors that do not exists should fail', async ({ page }, workerInfo) => { + const dbp = BrokerProtectionPage.create(page, workerInfo.project.use); + await dbp.enabled(); + await dbp.navigatesTo('clicks.html'); + await dbp.receivesAction('click-nonexistent-selector.json'); + const response = await dbp.collector.waitForMessage('actionCompleted'); + + dbp.isErrorMessage(response); + }); + + test('clicking buttons that are disabled should fail', async ({ page }, workerInfo) => { + const dbp = BrokerProtectionPage.create(page, workerInfo.project.use); + await dbp.enabled(); + await dbp.navigatesTo('clicks.html'); + await dbp.receivesAction('click-disabled-button.json'); + const response = await dbp.collector.waitForMessage('actionCompleted'); + + dbp.isErrorMessage(response); + }); + + test('clicking selectors that do not exist when failSilently is enabled should not fail', async ({ page }, workerInfo) => { + const dbp = BrokerProtectionPage.create(page, workerInfo.project.use); + await dbp.enabled(); + await dbp.navigatesTo('clicks.html'); + await dbp.receivesAction('click-nonexistent-selector-failSilently.json'); + const response = await dbp.collector.waitForMessage('actionCompleted'); + + dbp.isSuccessMessage(response); + }); + + test('clicking buttons that are disabled when failSilently is enabled should not fail', async ({ page }, workerInfo) => { + const dbp = BrokerProtectionPage.create(page, workerInfo.project.use); + await dbp.enabled(); + await dbp.navigatesTo('clicks.html'); + await dbp.receivesAction('click-disabled-button-failSilently.json'); + const response = await dbp.collector.waitForMessage('actionCompleted'); + + dbp.isSuccessMessage(response); + }); + test('getCaptchaInfo', async ({ page }, workerInfo) => { const dbp = BrokerProtectionPage.create(page, workerInfo.project.use); await dbp.enabled(); diff --git a/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button-failSilently.json b/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button-failSilently.json new file mode 100644 index 0000000000..d83e149475 --- /dev/null +++ b/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button-failSilently.json @@ -0,0 +1,16 @@ +{ + "state": { + "action": { + "actionType": "click", + "id": "1", + "elements": [ + { + "type": "button", + "selector": ".btn", + "failSilently": true + } + ] + } + } + } + \ No newline at end of file diff --git a/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button.json b/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button.json new file mode 100644 index 0000000000..b13e87c312 --- /dev/null +++ b/injected/integration-test/test-pages/broker-protection/actions/click-disabled-button.json @@ -0,0 +1,15 @@ +{ + "state": { + "action": { + "actionType": "click", + "id": "1", + "elements": [ + { + "type": "button", + "selector": ".btn" + } + ] + } + } + } + \ No newline at end of file diff --git a/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector-failSilently.json b/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector-failSilently.json new file mode 100644 index 0000000000..2d77354350 --- /dev/null +++ b/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector-failSilently.json @@ -0,0 +1,16 @@ +{ + "state": { + "action": { + "actionType": "click", + "id": "1", + "elements": [ + { + "type": "button", + "selector": ".test", + "failSilently": true + } + ] + } + } + } + \ No newline at end of file diff --git a/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector.json b/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector.json new file mode 100644 index 0000000000..8aa7698e15 --- /dev/null +++ b/injected/integration-test/test-pages/broker-protection/actions/click-nonexistent-selector.json @@ -0,0 +1,15 @@ +{ + "state": { + "action": { + "actionType": "click", + "id": "1", + "elements": [ + { + "type": "button", + "selector": ".test" + } + ] + } + } + } + \ No newline at end of file diff --git a/injected/integration-test/test-pages/broker-protection/pages/clicks.html b/injected/integration-test/test-pages/broker-protection/pages/clicks.html new file mode 100644 index 0000000000..13d06d3b00 --- /dev/null +++ b/injected/integration-test/test-pages/broker-protection/pages/clicks.html @@ -0,0 +1,20 @@ + + + + + + Broker Protection + + +
+
John Doe
+
32
+
+ New York, NY + Los Angeles, CA + View More +
+ +
+ + \ No newline at end of file diff --git a/injected/src/features/broker-protection/actions/click.js b/injected/src/features/broker-protection/actions/click.js index 7beed13f0f..c08745f36f 100644 --- a/injected/src/features/broker-protection/actions/click.js +++ b/injected/src/features/broker-protection/actions/click.js @@ -51,6 +51,10 @@ export function click(action, userData, root = document) { const elements = getElements(rootElement, element.selector); if (!elements?.length) { + if (element.failSilently) { + return new SuccessResponse({ actionID: action.id, actionType: action.actionType, response: null }); + } + return new ErrorResponse({ actionID: action.id, message: `could not find element to click with selector '${element.selector}'!`, @@ -63,7 +67,7 @@ export function click(action, userData, root = document) { const elem = elements[i]; if ('disabled' in elem) { - if (elem.disabled) { + if (elem.disabled && !element.failSilently) { return new ErrorResponse({ actionID: action.id, message: `could not click disabled element ${element.selector}'!` }); } }