TypeError: Cannot read properties of undefined (reading 'defaults')
Hello,
Am facing below error, I have set the OPENAI_API_KEY in .env file and also set in my systems environment variables, but still facing the error. Can anyone pls help me as am exploring this new AI feature to integrate into automation framework.
TypeError: Cannot read properties of undefined (reading 'defaults')
13 | const aiArgs = { page, test }
14 | await page.waitForTimeout(3000)
> 15 | await auto(`Type "auto-playwright" in the search box`, aiArgs, options)
| ^
16 | await auto('Press enter', aiArgs, options)
17 | await page.waitForTimeout(5000)
Response is very much appreciated, TIA.
@lucgagan , could you pls help to resolve the issue.
Alright just raised a PR https://github.com/lucgagan/auto-playwright/pull/40
@rajeshdavidbabu , still am facing the defaults issue after updating the import statement at per your latest, so it would be great to help me for the solution.
Reviewing this autoplaywright for a hackathon project and the current version is unusable without a fix for
TypeError: Cannot read properties of undefined (reading 'defaults') at sanitizeHtml (c:\repo\POC Stuff\AutoPlaywright\node_modules\auto-playwright\dist\sanitizeHtml.js:23:46) at getSnapshot (c:\repo\POC Stuff\AutoPlaywright\node_modules\auto-playwright\dist\getSnapshot.js:7:46) at runTask (c:\repo\POC Stuff\AutoPlaywright\node_modules\auto-playwright\dist\auto.js:37:19) at node_modules\auto-playwright\dist\auto.js:17:24 at tests\auto-examples.spec.ts:7:3
I am also facing the same issue though OpenAI API_Key is set in environment variable,
TypeError: Cannot read properties of undefined (reading 'defaults')
7 | // `auto` can query data
8 | // In this case, the result is plain-text contents of the header
> 9 | const headerText = await auto(
| ^
10 | "get the header text",
11 | { page, test },
12 | );
Same error. Basic setup of playwright inside of NX. Basically unusable library.
I've revert the sanitizeHtml.ts import from import * as sanitizeHtml from 'sanitize-html'; to import sanitize from "sanitize-html"; And, I tested it locally and also using an npm build.
Having the same issue, noticed couple of issues related to this and some PRs but it's not clear what needs to be done to get this working properly. Anyone who has got this to work correctly?
Is there an update on this issue? None of the solutions given work.
Any update on this issue, im not able to resolve it
Joining the comments above, I have the same issue.
"auto-playwright": "^1.16.0",
Joining the comment, I have the same issue also @rajeshdavidbabu
Great suggestion in another thread, until a new release is ready, replace the contents of:
node_modules\auto-playwright\dist\sanitizeHtml.js
With:
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.sanitizeHtml = void 0;
const sanitize = require("sanitize-html");
/**
* The reason for sanitization is because OpenAI does not need all of the HTML tags
* to know how to interpret the website, e.g. it will not make a difference to AI if
* we include or exclude <script> tags as they do not impact the already rendered DOM.
*
* In my experience, reducing HTML only to basic tags produces faster and more reliable prompts.
*
* Note that the output of this function is designed to interpret only the HTML tags.
* For instructions that rely on visual cues (e.g. "click red button") we intend to
* combine HTML with screenshots in the future versions of this library.
*/
const sanitizeHtml = (subject) => {
return sanitize(subject, {
// The default allowedTags list already includes _a lot_ of commonly used tags.
// https://www.npmjs.com/package/sanitize-html#default-options
//
// I don't see a need for this to be configurable at the moment,
// as it already covers all the layout tags, but we can revisit this if necessary.
allowedTags: sanitize.defaults.allowedTags.concat([
"button",
"form",
"img",
"input",
"select",
"textarea",
]),
// Setting allowedAttributes to false will allow all attributes.
allowedAttributes: false,
});
};
exports.sanitizeHtml = sanitizeHtml;
I went down to 1.14.0 and it was "working". However I feel like the tool isn't stable and it is very expensive in GPT requests. The temp solution is working fine on my local but can't be deployed.