export const pageBindings = ['setElementStyles'];Note: this is not `PageBinding` in the terms we usually use for CDP.
See FREESTYLER_BINDING_NAME and CDP `Runtime.addBinding` for more context.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +1 |
| Commit-Queue | +2 |
Note: this is not `PageBinding` in the terms we usually use for CDP.
See FREESTYLER_BINDING_NAME and CDP `Runtime.addBinding` for more context.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
export function stringifyErrorOnThePage(this: Error, executedCode: string[], bindingFunctions: string[]): string {let's only return `this.stack` from this function and handle the stack trace parsing in the DevTools context (stringifyErrorOnThePage runs in the page context).
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Auto-Submit | +0 |
export function stringifyErrorOnThePage(this: Error, executedCode: string[], bindingFunctions: string[]): string {let's only return `this.stack` from this function and handle the stack trace parsing in the DevTools context (stringifyErrorOnThePage runs in the page context).
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
if (!this.stack) {I think this if is redundant. If stack is not there, it is not be serialised to json if it is undefined.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
I think this if is redundant. If stack is not there, it is not be serialised to json if it is undefined.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Code-Review | +1 |
LGTM, with some comments and nits.
if (this instanceof Error) {Do we need this, now what we branch out the error?
let res;I don't think we need to use a let here, each branch returns.
const stackLines = lines.map(curr => curr.trim()).filter((trimmedLine: string) => {Unnecessary type cast `trimmedLine: string` as it is already inferred.
// based on the filter above we can assume we have at least 2 elements in splittedStackLine at this pointDo we need to do that in the above filter, or we can move it to this find with return false?
const functionLines = functionDeclaration?.split('\n');Nit: Unnecessary optional chaining
const executedCode = functionLines[lineNum];I think here we mean error line?
freestyler.id, {args: JSON.stringify(args), element: args.element, resolve, reject, error: args.error});Super nit: Comma after args.error to keep the diff minimal.
export const pageExposedFunctions = ['setElementStyles'];Nit: This is const and should follow naming convention - capital letters, _ as separator.
{method: 'setElementStyles', selector, className, styles, element: el, error: bindingError});Super Nit: you can keep as smaller diff if you add `,` after bindingError
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
if (this instanceof Error) {Do we need this, now what we branch out the error?
Probably not, removed!
let res;I don't think we need to use a let here, each branch returns.
Done
const stackLines = lines.map(curr => curr.trim()).filter((trimmedLine: string) => {Unnecessary type cast `trimmedLine: string` as it is already inferred.
Done
// based on the filter above we can assume we have at least 2 elements in splittedStackLine at this pointDo we need to do that in the above filter, or we can move it to this find with return false?
We can move it without problems I believe!
const functionLines = functionDeclaration?.split('\n');Nicholas RoscinoNit: Unnecessary optional chaining
Done
const executedCode = functionLines[lineNum];I think here we mean error line?
Marked as resolved.
freestyler.id, {args: JSON.stringify(args), element: args.element, resolve, reject, error: args.error});Super nit: Comma after args.error to keep the diff minimal.
Done
export const pageExposedFunctions = ['setElementStyles'];Nit: This is const and should follow naming convention - capital letters, _ as separator.
Acknowledged
{method: 'setElementStyles', selector, className, styles, element: el, error: bindingError});Super Nit: you can keep as smaller diff if you add `,` after bindingError
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Commit-Queue | +2 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
11 is the latest approved patch-set.
The change was submitted with unreviewed changes in the following files:
```
The name of the file: front_end/models/ai_assistance/EvaluateAction.ts
Insertions: 14, Deletions: 15.
@@ -5,7 +5,7 @@
import * as SDK from '../../core/sdk/sdk.js';
import * as Protocol from '../../generated/protocol.js';
-import {pageExposedFunctions} from './injected.js';
+import {PAGE_EXPOSED_FUNCTIONS} from './injected.js';
export function formatError(message: string): string {
return `Error: ${message}`;
@@ -24,9 +24,6 @@
/* istanbul ignore next */
export function stringifyObjectOnThePage(this: unknown): string {
- if (this instanceof Error) {
- return `Error: ${this.message}`;
- }
const seenBefore = new WeakMap();
return JSON.stringify(this, function replacer(this: unknown, key: string, value: unknown) {
if (typeof value === 'object' && value !== null) {
@@ -72,9 +69,8 @@
case Protocol.Runtime.RemoteObjectType.Function:
return `${object.description}`;
case Protocol.Runtime.RemoteObjectType.Object: {
- let res;
if (object.subtype === 'error') {
- res = await object.callFunctionJSON(getErrorStackOnThePage, []);
+ const res = await object.callFunctionJSON(getErrorStackOnThePage, []);
if (!res) {
throw new Error('Could not stringify the object' + object);
@@ -82,7 +78,7 @@
return EvaluateAction.stringifyError(res, functionDeclaration);
}
- res = await object.callFunction(stringifyObjectOnThePage);
+ const res = await object.callFunction(stringifyObjectOnThePage);
if (!res.object || res.object.type !== Protocol.Runtime.RemoteObjectType.String) {
throw new Error('Could not stringify the object' + object);
@@ -143,13 +139,16 @@
static getExecutedLineFromStack(stack: string, pageExposedFunctions: string[]): number|null {
const lines = stack.split('\n');
- const stackLines = lines.map(curr => curr.trim()).filter((trimmedLine: string) => {
- return trimmedLine.startsWith('at') && trimmedLine.split(' ').length >= 2;
+ const stackLines = lines.map(curr => curr.trim()).filter(trimmedLine => {
+ return trimmedLine.startsWith('at');
});
const selectedStack = stackLines.find(stackLine => {
const splittedStackLine = stackLine.split(' ');
- // based on the filter above we can assume we have at least 2 elements in splittedStackLine at this point
+
+ if (splittedStackLine.length < 2) {
+ return false;
+ }
const signature = splittedStackLine[1] === 'async' ?
splittedStackLine[2] : // if the stack line contains async the function name is the next element
@@ -185,18 +184,18 @@
return `Error: ${result.message}`;
}
- const lineNum = EvaluateAction.getExecutedLineFromStack(result.stack, pageExposedFunctions);
+ const lineNum = EvaluateAction.getExecutedLineFromStack(result.stack, PAGE_EXPOSED_FUNCTIONS);
if (!lineNum) {
return `Error: ${result.message}`;
}
- const functionLines = functionDeclaration?.split('\n');
+ const functionLines = functionDeclaration.split('\n');
- const executedCode = functionLines[lineNum];
- if (!executedCode) {
+ const errorLine = functionLines[lineNum];
+ if (!errorLine) {
return `Error: ${result.message}`;
}
- return `Error: executing the line "${executedCode.trim()}" failed with the following error:\n${result.message}`;
+ return `Error: executing the line "${errorLine.trim()}" failed with the following error:\n${result.message}`;
}
}
```
```
The name of the file: front_end/models/ai_assistance/injected.ts
Insertions: 16, Deletions: 5.
@@ -55,8 +55,13 @@
if (!global.freestyler) {
const freestyler = (args: FreestyleCallbackArgs): Promise<string> => {
const {resolve, reject, promise} = Promise.withResolvers<string>();
- freestyler.callbacks.set(
- freestyler.id, {args: JSON.stringify(args), element: args.element, resolve, reject, error: args.error});
+ freestyler.callbacks.set(freestyler.id, {
+ args: JSON.stringify(args),
+ element: args.element,
+ resolve,
+ reject,
+ error: args.error,
+ });
// @ts-expect-error this is binding added though CDP
globalThis[bindingName](String(freestyler.id));
freestyler.id++;
@@ -90,7 +95,7 @@
export const freestylerBinding = `(${String(freestylerBindingFunc)})('${FREESTYLER_BINDING_NAME}')`;
-export const pageExposedFunctions = ['setElementStyles'];
+export const PAGE_EXPOSED_FUNCTIONS = ['setElementStyles'];
/**
* Please see fileoverview
@@ -141,8 +146,14 @@
const bindingError = new Error();
- const result = await global.freestyler(
- {method: 'setElementStyles', selector, className, styles, element: el, error: bindingError});
+ const result = await global.freestyler({
+ method: 'setElementStyles',
+ selector,
+ className,
+ styles,
+ element: el,
+ error: bindingError,
+ });
const rootNode = el.getRootNode();
if (rootNode instanceof ShadowRoot) {
```
Adds failing line to the error for JS evaluations executed by CSS Agent
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |