Skip to content

Allow CAPTCHA actions to fail silently #1622

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

brianhall
Copy link
Contributor

@brianhall brianhall commented Apr 9, 2025

Asana Task/Github Issue: https://app.asana.com/0/1199230911884351/1209924515943923/f

Description

Allows captcha actions to fail silently without stopping the opt out flow for more flexbility

Testing Steps

See Asana

Checklist

Please tick all that apply:

  • I have tested this change locally
  • I have tested this change locally in all supported browsers
  • This change will be visible to users
  • I have added automated tests that cover this change
  • I have ensured the change is gated by config
  • This change was covered by a ship review
  • This change was covered by a tech design
  • Any dependent config has been merged

Copy link

netlify bot commented Apr 9, 2025

Deploy Preview for content-scope-scripts ready!

Name Link
🔨 Latest commit 91212eb
🔍 Latest deploy log https://app.netlify.com/sites/content-scope-scripts/deploys/67f63b96b2db3500083cf1c6
😎 Deploy Preview https://deploy-preview-1622--content-scope-scripts.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

github-actions bot commented Apr 9, 2025

Temporary Branch Update

The temporary branch has been updated with the latest changes. Below are the details:

Please use the above install command to update to the latest version.

Copy link

github-actions bot commented Apr 9, 2025

[Beta] Generated file diff

Time updated: Wed, 09 Apr 2025 09:19:54 GMT

Android
    - android/brokerProtection.js

File has changed

Integration
    - integration/contentScope.js

File has changed

Windows
    - windows/contentScope.js

File has changed

Apple
    - dist/contentScopeIsolated.js

File has changed

@brianhall brianhall marked this pull request as ready for review April 9, 2025 09:19
@brianhall brianhall requested review from shakyShane and a team as code owners April 9, 2025 09:19
Copy link
Contributor

@madblex madblex left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a few comments that I think should be addressed, but I am also mindful we're on a tight schedule, so I'll be approving this (pending testing) since nothing is strictly blocking.

Comment on lines +143 to +145
function emptySuccessResponse(actionID, actionType) {
return SuccessResponse.create({ actionID, actionType, response: {} });
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'd say this makes more sense as part of the SuccessResponse class:

    /**
     * @param {Pick<SuccessResponseInterface, "actionID" | "actionType">} params
     * @return {SuccessResponse}
     */
    static createEmptySuccessResponse(params) {
        return SuccessResponse.create({ ...params, response: {} });
    }

and usage becomes:

  return SuccessResponse.createEmptySuccessResponse({ actionID, actionType })

@@ -12,6 +12,7 @@
* @property {string} [captchaType]
* @property {string} [injectCaptchaHandler]
* @property {string} [dataSource]
* @property {boolean} [failSilently]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

failSilently suggests we are allowing something to fail silently when in reality we're just skipping the action in case of failure, can we consider something on the lines of: bypassOnFailure | bypassOnError | skipOnError?

@@ -64,17 +64,19 @@ export function getCaptchaInfo(action, root = document) {

const captchaContainer = getCaptchaContainer(root, selector);
if (PirError.isError(captchaContainer)) {
return createError(captchaContainer.error.message);
return failSilently ? emptySuccessResponse(actionID, actionType) : createError(captchaContainer.error.message);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think failSilently is a property of any action and it should be moved a level up (as part of injected/src/features/broker-protection/execute.js)

export async function execute(action, inputData, root = document) {
    try {
        const executeAction = async () => {
            switch (action.actionType) {
                case 'navigate':
                    return navigate(action, data(action, inputData, 'userProfile'));
                case 'extract':
                    return await extract(action, data(action, inputData, 'userProfile'), root);
                case 'click':
                    return click(action, data(action, inputData, 'userProfile'), root);
                case 'expectation':
                    return expectation(action, root);
                case 'fillForm':
                    return fillForm(action, data(action, inputData, 'extractedProfile'), root);
                case 'getCaptchaInfo':
                    return getCaptchaInfo(action, root);
                case 'solveCaptcha':
                    return solveCaptcha(action, data(action, inputData, 'token'), root);
                default: {
                    return new ErrorResponse({
                        actionID: action.id,
                        message: `unimplemented actionType: ${action.actionType}`,
                    });
                }
            }
        };

        const actionResponse = await executeAction();
        if (action.failSilently) {
            return SuccessResponse.createEmptySuccessResponse({ actionID: action.id, actionType: action.actionType });
        }
        return actionResponse;
    } catch (e) {
        // ...
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants