{"action":"created","issue":{"url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2170","repository_url":"https://api.github.com/repos/GoogleChrome/puppeteer","labels_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2170/labels{/name}","comments_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2170/comments","events_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2170/events","html_url":"https://github.com/GoogleChrome/puppeteer/issues/2170","id":303735258,"number":2170,"title":"exposeFunction() does not work after goto()","user":{"login":"IAmJulianAcosta","id":1844640,"avatar_url":"https://avatars1.githubusercontent.com/u/1844640?v=4","gravatar_id":"","url":"https://api.github.com/users/IAmJulianAcosta","html_url":"https://github.com/IAmJulianAcosta","followers_url":"https://api.github.com/users/IAmJulianAcosta/followers","following_url":"https://api.github.com/users/IAmJulianAcosta/following{/other_user}","gists_url":"https://api.github.com/users/IAmJulianAcosta/gists{/gist_id}","starred_url":"https://api.github.com/users/IAmJulianAcosta/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/IAmJulianAcosta/subscriptions","organizations_url":"https://api.github.com/users/IAmJulianAcosta/orgs","repos_url":"https://api.github.com/users/IAmJulianAcosta/repos","events_url":"https://api.github.com/users/IAmJulianAcosta/events{/privacy}","received_events_url":"https://api.github.com/users/IAmJulianAcosta/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2018-03-09T06:11:47Z","updated_at":"2018-03-14T23:30:56Z","closed_at":null,"author_association":"NONE","body":"### Steps to reproduce\r\n\r\n**Tell us about your environment:**\r\n\r\n* Puppeteer version: 1.1.1\r\n* Platform / OS version: Ubuntu 16.04 / Chromium revision 510398\r\n* Node.js version: 8.6.0\r\n\r\n**What steps will reproduce the problem?**\r\n1. Create a new page\r\n2. Navigate to a page\r\n3. Try to expose a function using `page.exposeFunction()`\r\n4. Access the function in browser\r\n\r\n_Please include code that reproduces the issue._\r\n```\r\nconst puppeteer = require('puppeteer');\r\n\r\npuppeteer.launch().then(async browser => {\r\n  const page = await browser.newPage();\r\n  await page.goto('https://google.com');\r\n  await page.exposeFunction('foo', () => {\r\n    console.log('foo')\r\n  });\r\n});\r\n```\r\n**What is the expected result?**\r\nOpen chromium console, type `window.foo`, should be a function\r\n\r\n**What happens instead?**\r\n`window.foo = undefined`\r\n\r\n=============================\r\nBut if `exposeFunction()` is called BEFORE `goto`, `window.foo` is available in browser:\r\n\r\n```\r\nconst puppeteer = require('puppeteer');\r\n\r\npuppeteer.launch().then(async browser => {\r\n  const page = await browser.newPage();\r\n  await page.exposeFunction('foo', () => {\r\n    console.log('foo')\r\n  });\r\n  await page.goto('https://google.com'); //This works\r\n});\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/comments/373209221","html_url":"https://github.com/GoogleChrome/puppeteer/issues/2170#issuecomment-373209221","issue_url":"https://api.github.com/repos/GoogleChrome/puppeteer/issues/2170","id":373209221,"user":{"login":"JoelEinbinder","id":4624233,"avatar_url":"https://avatars1.githubusercontent.com/u/4624233?v=4","gravatar_id":"","url":"https://api.github.com/users/JoelEinbinder","html_url":"https://github.com/JoelEinbinder","followers_url":"https://api.github.com/users/JoelEinbinder/followers","following_url":"https://api.github.com/users/JoelEinbinder/following{/other_user}","gists_url":"https://api.github.com/users/JoelEinbinder/gists{/gist_id}","starred_url":"https://api.github.com/users/JoelEinbinder/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JoelEinbinder/subscriptions","organizations_url":"https://api.github.com/users/JoelEinbinder/orgs","repos_url":"https://api.github.com/users/JoelEinbinder/repos","events_url":"https://api.github.com/users/JoelEinbinder/events{/privacy}","received_events_url":"https://api.github.com/users/JoelEinbinder/received_events","type":"User","site_admin":false},"created_at":"2018-03-14T23:30:56Z","updated_at":"2018-03-14T23:30:56Z","author_association":"COLLABORATOR","body":"I can't reproduce with this code:\r\n\r\n```js\r\nconst puppeteer = require('puppeteer');\r\n\r\npuppeteer.launch().then(async browser => {\r\n  const page = await browser.newPage();\r\n  await page.exposeFunction('woo', () => {\r\n    console.log('woo');\r\n  });\r\n  await page.goto('https://www.example.com');\r\n  await page.exposeFunction('foo', () => {\r\n    console.log('foo');\r\n  });\r\n  console.log('Has foo?', await page.evaluate('!!window.foo'));\r\n  console.log('Has woo?', await page.evaluate('!!window.woo'));\r\n  await browser.close();\r\n});\r\n```\r\n\r\nCan you try it out?"}}
{"actor":{"display_login":"JoelEinbinder"}}