Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,6 @@
+ [jsHandle.getProperties()](#jshandlegetproperties)
+ [jsHandle.getProperty(propertyName)](#jshandlegetpropertypropertyname)
+ [jsHandle.jsonValue()](#jshandlejsonvalue)
+ [jsHandle.toString()](#jshandletostring)
* [class: ElementHandle](#class-elementhandle)
+ [elementHandle.asElement()](#elementhandleaselement)
+ [elementHandle.boundingBox()](#elementhandleboundingbox)
Expand Down Expand Up @@ -1509,9 +1508,6 @@ Returns a JSON representation of the object. The JSON is generated by running [`

> **NOTE** The method will throw if the referenced object is not stringifiable.

#### jsHandle.toString()
- returns: <[string]>

### class: ElementHandle

> **NOTE** Class [ElementHandle] extends [JSHandle].
Expand Down
2 changes: 1 addition & 1 deletion lib/ExecutionContext.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class JSHandle {
const type = this._remoteObject.subtype || this._remoteObject.type;
return 'JSHandle@' + type;
}
return helper.valueFromRemoteObject(this._remoteObject) + '';
return 'JSHandle:' + helper.valueFromRemoteObject(this._remoteObject);
}
}

Expand Down
11 changes: 9 additions & 2 deletions lib/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,15 @@ class Page extends EventEmitter {
return;
}
const values = event.args.map(arg => this._frameManager.createJSHandle(event.executionContextId, arg));
const text = values.join(' ');
const message = new ConsoleMessage(event.type, text, values);
const textTokens = [];
for (let i = 0; i < event.args.length; ++i) {
const remoteObject = event.args[i];
if (remoteObject.objectId)
textTokens.push(values[i].toString());
else
textTokens.push(helper.valueFromRemoteObject(remoteObject));
}
const message = new ConsoleMessage(event.type, textTokens.join(' '), values);
this.emit(Page.Events.Console, message);
}

Expand Down
6 changes: 4 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ describe('Page', function() {

describe('JSHandle.toString', function() {
it('should work for primitives', SX(async function() {
const aHandle = await page.evaluateHandle(() => 2);
expect(aHandle.toString()).toBe('2');
const numberHandle = await page.evaluateHandle(() => 2);
expect(numberHandle.toString()).toBe('JSHandle:2');
const stringHandle = await page.evaluateHandle(() => 'a');
expect(stringHandle.toString()).toBe('JSHandle:a');
}));
it('should work for complicated objects', SX(async function() {
const aHandle = await page.evaluateHandle(() => window);
Expand Down
1 change: 1 addition & 0 deletions utils/doclint/check_public_api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const EXCLUDE_CLASSES = new Set([
const EXCLUDE_METHODS = new Set([
'Headers.fromPayload',
'Page.create',
'JSHandle.toString',
]);

/**
Expand Down