Skip to content
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

TypeError: Cannot read properties of undefined (reading 'defaults') in auto-playwright #33

Open
galaczi opened this issue Jun 24, 2024 · 7 comments

Comments

@galaczi
Copy link

galaczi commented Jun 24, 2024

I am encountering a TypeError when using the auto function from the auto-playwright library in conjunction with crawlee. The error message indicates that the defaults property is undefined in the sanitize-html library, which is used internally by auto-playwright.

Steps to Reproduce:

Install the latest versions of auto-playwright and sanitize-html.
Set up a route handler using crawlee (routes.ts) and auto-playwright as shown below:

import { createPlaywrightRouter } from 'crawlee';
import { auto } from 'auto-playwright';

export const router = createPlaywrightRouter();

router.addDefaultHandler(async ({ page, log }) => {
    try {
        await auto('Click the start button', { page });
    } catch (error) {
        log.error(`Error in auto-playwright: ${error.message}`);
    }
});

Run the crawler.

The following error is thrown:

TypeError: Cannot read properties of undefined (reading 'defaults')
    at sanitizeHtml (/path/to/node_modules/auto-playwright/dist/sanitizeHtml.js:23:46)
    at getSnapshot (/path/to/node_modules/auto-playwright/dist/getSnapshot.js:7:46)
    at async runTask (/path/to/node_modules/auto-playwright/dist/auto.js:37:19)
    at async auto (/path/to/node_modules/auto-playwright/dist/auto.js:14:16)
    at <anonymous> (/path/to/project/src/routes.ts:8:5)

Additional Information:

The issue seems related to the sanitize-html library and its type definitions.
I have verified that I am using the latest versions of both auto-playwright and sanitize-html.
The problem persists despite the issue being marked as resolved in version 1.12.2 of auto-playwright.

Environment:

Node.js version: v20.13.1
auto-playwright version: 1.15.0
sanitize-html version: 2.13.0
Operating System: Ubuntu

References:

GitHub Issue #7 - Similar issue reported and marked as resolved.

Possible Workaround:

Manually adjust the sanitizeHtml function in the auto-playwright library to ensure it correctly references sanitize-html:

const sanitizeHtml = (subject) => {
    return sanitize(subject, {
        allowedTags: sanitize.defaults.allowedTags.concat([
            "button",
            "form",
            "img",
            "input",
            "select",
            "textarea",
        ]),
        allowedAttributes: false,
    });
};

Thank you!

@rajeshdavidbabu
Copy link
Contributor

I think this might be due to the completeTask file not working properly. I have fixed it in my latest PR. Can you check if it fixes it ?

@billw4
Copy link

billw4 commented Jul 11, 2024

I've encountered this issue as well this morning. Using version 1.16.0.

@Randy705
Copy link

Got the same issue as well. Using version: 1.16.0

@rubickecho
Copy link

yes, i am too, 1.16.0

@rajeshdavidbabu
Copy link
Contributor

Yeah you are right sanitizeHtml.

@rajeshdavidbabu
Copy link
Contributor

Just raised a PR #40 with explanation lets wait for @lucgagan to approve

@jvrdelafuente
Copy link

Could we get a release that includes this change? I tested it by using the repository directly, and I can confirm that it resolved the issue on my end.

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

No branches or pull requests

6 participants