{"action":"created","issue":{"url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2585","repository_url":"https://api.github.com/repos/GoogleChrome/puppeteer","labels_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2585/labels{/name}","comments_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2585/comments","events_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2585/events","html_url":"https://github.com/GoogleChrome/puppeteer/issues/2585","id":325206177,"node_id":"MDU6SXNzdWUzMjUyMDYxNzc=","number":2585,"title":"Evaluating a function on a JS Handle","user":{"login":"mathurs","id":2851262,"node_id":"MDQ6VXNlcjI4NTEyNjI=","avatar_url":"https://avatars3.githubusercontent.com/u/2851262?v=4","gravatar_id":"","url":"https://api.github.com/users/mathurs","html_url":"https://github.com/mathurs","followers_url":"https://api.github.com/users/mathurs/followers","following_url":"https://api.github.com/users/mathurs/following{/other_user}","gists_url":"https://api.github.com/users/mathurs/gists{/gist_id}","starred_url":"https://api.github.com/users/mathurs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathurs/subscriptions","organizations_url":"https://api.github.com/users/mathurs/orgs","repos_url":"https://api.github.com/users/mathurs/repos","events_url":"https://api.github.com/users/mathurs/events{/privacy}","received_events_url":"https://api.github.com/users/mathurs/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-05-22T09:14:50Z","updated_at":"2018-06-21T16:23:02Z","closed_at":"2018-05-31T07:00:28Z","author_association":"NONE","body":"I am new to exploring this project and maybe there is already a way to do this in a better fashion. However, it seems currently, once in a JS handle context, we can only getProperty/getProperties on it. Would it make sense to evaluate an arbitrary function on it.\r\n\r\nI need this because there are many use cases where selection of an element is done outside of $eval. Once a JSHandle is selected (among many returned by $$), its currently difficult to run arbitrary functions on it, like getting style values or such.\r\n\r\nSomething along the lines\r\n`  /**\r\n   * @param {string} propertyName\r\n   * @return {!Promise<?JSHandle>}\r\n   */\r\n  async evaluateToProperty(propertyFunction, propertyName) {\r\n    const objectHandle = await this._context.evaluateHandle((object, propertyFunction, propertyName) => {\r\n      const result = {__proto__: null};\r\n      const expression = new Function('e', propertyFunction);\r\n      result[propertyName] = expression(object);\r\n      return result;\r\n    }, this, propertyFunction, propertyName);\r\n    const properties = await objectHandle.getProperties();\r\n    const result = properties.get(propertyName) || null;\r\n    await objectHandle.dispose();\r\n    return result;\r\n  }\r\n`\r\nwhich can be used as\r\n`await element.evaluateToProperty('return e.children.length', 'children')`\r\n\r\nThanks,\r\nSaurabh"},"comment":{"url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/comments/399162741","html_url":"https://github.com/GoogleChrome/puppeteer/issues/2585#issuecomment-399162741","issue_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2585","id":399162741,"node_id":"MDEyOklzc3VlQ29tbWVudDM5OTE2Mjc0MQ==","user":{"login":"mathurs","id":2851262,"node_id":"MDQ6VXNlcjI4NTEyNjI=","avatar_url":"https://avatars3.githubusercontent.com/u/2851262?v=4","gravatar_id":"","url":"https://api.github.com/users/mathurs","html_url":"https://github.com/mathurs","followers_url":"https://api.github.com/users/mathurs/followers","following_url":"https://api.github.com/users/mathurs/following{/other_user}","gists_url":"https://api.github.com/users/mathurs/gists{/gist_id}","starred_url":"https://api.github.com/users/mathurs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mathurs/subscriptions","organizations_url":"https://api.github.com/users/mathurs/orgs","repos_url":"https://api.github.com/users/mathurs/repos","events_url":"https://api.github.com/users/mathurs/events{/privacy}","received_events_url":"https://api.github.com/users/mathurs/received_events","type":"User","site_admin":false},"created_at":"2018-06-21T16:23:02Z","updated_at":"2018-06-21T16:23:02Z","author_association":"NONE","body":"This worked. Thanks a lot!"}}
{"actor":{"display_login":"mathurs"}}