{"action":"created","issue":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/1240","labels_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1240/labels{/name}","comments_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1240/comments","events_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1240/events","html_url":"https://github.com/tmpvar/jsdom/issues/1240","id":107406525,"number":1240,"title":"help porting old 3.x code using window.run","user":{"login":"kapouer","id":131406,"avatar_url":"https://avatars.githubusercontent.com/u/131406?v=3","gravatar_id":"","url":"https://api.github.com/users/kapouer","html_url":"https://github.com/kapouer","followers_url":"https://api.github.com/users/kapouer/followers","following_url":"https://api.github.com/users/kapouer/following{/other_user}","gists_url":"https://api.github.com/users/kapouer/gists{/gist_id}","starred_url":"https://api.github.com/users/kapouer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kapouer/subscriptions","organizations_url":"https://api.github.com/users/kapouer/orgs","repos_url":"https://api.github.com/users/kapouer/repos","events_url":"https://api.github.com/users/kapouer/events{/privacy}","received_events_url":"https://api.github.com/users/kapouer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-09-20T17:44:05Z","updated_at":"2015-09-20T17:57:06Z","closed_at":null,"body":"Hi,\r\n\r\nin a small project i used to `window.run(scriptStr)` and also i was able to set `window.somefunc` from outside the window context and call it from inside the window context.\r\nI started by trying\r\n```\r\nvar context = require('vm').createContext(window);\r\nvar vmscript = new (require('vm').Script)(script);\r\nvmscript.runInContext(context);\r\n```\r\nBut somehow it feels wrong. Is it ?"},"comment":{"url":"https://api.github.com/repos/tmpvar/jsdom/issues/comments/141815370","html_url":"https://github.com/tmpvar/jsdom/issues/1240#issuecomment-141815370","issue_url":"https://api.github.com/repos/tmpvar/jsdom/issues/1240","id":141815370,"user":{"login":"domenic","id":617481,"avatar_url":"https://avatars.githubusercontent.com/u/617481?v=3","gravatar_id":"","url":"https://api.github.com/users/domenic","html_url":"https://github.com/domenic","followers_url":"https://api.github.com/users/domenic/followers","following_url":"https://api.github.com/users/domenic/following{/other_user}","gists_url":"https://api.github.com/users/domenic/gists{/gist_id}","starred_url":"https://api.github.com/users/domenic/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/domenic/subscriptions","organizations_url":"https://api.github.com/users/domenic/orgs","repos_url":"https://api.github.com/users/domenic/repos","events_url":"https://api.github.com/users/domenic/events{/privacy}","received_events_url":"https://api.github.com/users/domenic/received_events","type":"User","site_admin":false},"created_at":"2015-09-20T17:57:06Z","updated_at":"2015-09-20T17:57:06Z","body":"Yes, this relies on some internal details of jsdom, that will not necessarily always work the same way.\r\n\r\nThe best thing to do is to create a `<script>` tag and insert the code there.\r\n\r\n```js\r\nconst scriptEl = window.document.createElement(\"script\");\r\nscriptEl.textContent = script;\r\nwindow.document.body.appendChild(scriptEl);\r\n```"}}