{"action":"created","comment":{"url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/comments/92098393","pull_request_review_id":12607167,"id":92098393,"diff_hunk":"@@ -1,14 +1,22 @@\n-var noop = function(){};\n-var defaults = require('lodash.defaults');\n-var isEmpty = require('lodash.isempty');\n-var isFunction = require('lodash.isfunction');\n-var isArray = require('lodash.isarray');\n-var cloneDeep = require('lodash.clonedeep');\n-var BrowserWindow = require('electron').BrowserWindow;\n-var Menu = require('electron').Menu;\n+const noop = function(){};\n+const defaults = require('lodash.defaults');\n+const isEmpty = require('lodash.isempty');\n+const isFunction = require('lodash.isfunction');\n+const isArray = require('lodash.isarray');\n+const cloneDeep = require('lodash.clonedeep');\n+const electron = require('electron');\n+const remote = electron.remote;\n+const Menu = electron.Menu || remote.Menu;\n+const webContents = electron.webContents;\n \n+// this allows us to support users who remote.require this or users who run it\n+// directly in the renderer\n+const currentWebContents = (process.type === 'browser' ?\n+  webContents.getFocusedWebContents() :\n+  remote.getCurrentWebContents().webContents","path":"src/index.js","position":24,"original_position":24,"commit_id":"2fe9fa68793b4876867a51b5fd3b40b921a9fdcf","original_commit_id":"2fe9fa68793b4876867a51b5fd3b40b921a9fdcf","user":{"login":"ccnokes","id":1610343,"avatar_url":"https://avatars.githubusercontent.com/u/1610343?v=3","gravatar_id":"","url":"https://api.github.com/users/ccnokes","html_url":"https://github.com/ccnokes","followers_url":"https://api.github.com/users/ccnokes/followers","following_url":"https://api.github.com/users/ccnokes/following{/other_user}","gists_url":"https://api.github.com/users/ccnokes/gists{/gist_id}","starred_url":"https://api.github.com/users/ccnokes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccnokes/subscriptions","organizations_url":"https://api.github.com/users/ccnokes/orgs","repos_url":"https://api.github.com/users/ccnokes/repos","events_url":"https://api.github.com/users/ccnokes/events{/privacy}","received_events_url":"https://api.github.com/users/ccnokes/received_events","type":"User","site_admin":false},"body":"Strangely, both work. I'm not entirely sure why I have `.webContents` in there. I'll shorten it to `remote.getCurrentWebContents()`.","created_at":"2016-12-13T05:01:16Z","updated_at":"2016-12-13T05:01:17Z","html_url":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6#discussion_r92098393","pull_request_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6","_links":{"self":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/comments/92098393"},"html":{"href":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6#discussion_r92098393"},"pull_request":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6"}}},"pull_request":{"url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6","id":97256071,"html_url":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6","diff_url":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6.diff","patch_url":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6.patch","issue_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/6","number":6,"state":"open","locked":false,"title":"Support for <webview>s. Support requiring the module directly or via remote.require.","user":{"login":"ccnokes","id":1610343,"avatar_url":"https://avatars.githubusercontent.com/u/1610343?v=3","gravatar_id":"","url":"https://api.github.com/users/ccnokes","html_url":"https://github.com/ccnokes","followers_url":"https://api.github.com/users/ccnokes/followers","following_url":"https://api.github.com/users/ccnokes/following{/other_user}","gists_url":"https://api.github.com/users/ccnokes/gists{/gist_id}","starred_url":"https://api.github.com/users/ccnokes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccnokes/subscriptions","organizations_url":"https://api.github.com/users/ccnokes/orgs","repos_url":"https://api.github.com/users/ccnokes/repos","events_url":"https://api.github.com/users/ccnokes/events{/privacy}","received_events_url":"https://api.github.com/users/ccnokes/received_events","type":"User","site_admin":false},"body":"This addresses #5 and incidentally #4. \r\n\r\nI was sort of liberal with my changes on this than I'd normally be for a PR, so feel free to push back 😅. \r\n\r\nTo get it to work seamlessly in a webview, we need to know the current webContents the user is in. Getting the current BrowserWindow instance's webContents is incorrect -- that's the webview's parent renderer process and the `replaceMisspelling` will fail. Anyways, the easiest way to get the right webContents instance is `remote.getCurrentWebContents()`. But that breaks the suggested use case of `remote.require('electron-editor-context-menu')`. So I made both usages work, however, in webviews you have to just plain `require` it, `remote.require` won't work which I figured is acceptable because support for webviews is new. \r\n\r\nAutomated tests on something like this is a little hard I think, so I added an `example` folder with example usage in and out of a webview to make testing and development easier. I added it to `.npmignore` so that it's not inadvertently shipped in anyone's packaged app. \r\n\r\n","created_at":"2016-12-09T06:07:54Z","updated_at":"2016-12-13T05:01:17Z","closed_at":null,"merged_at":null,"merge_commit_sha":"f65fad11daa49310d1f46bb57ffbe4064e09a7a2","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6/commits","review_comments_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6/comments","review_comment_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/comments{/number}","comments_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/6/comments","statuses_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/statuses/2fe9fa68793b4876867a51b5fd3b40b921a9fdcf","head":{"label":"ccnokes:master","ref":"master","sha":"2fe9fa68793b4876867a51b5fd3b40b921a9fdcf","user":{"login":"ccnokes","id":1610343,"avatar_url":"https://avatars.githubusercontent.com/u/1610343?v=3","gravatar_id":"","url":"https://api.github.com/users/ccnokes","html_url":"https://github.com/ccnokes","followers_url":"https://api.github.com/users/ccnokes/followers","following_url":"https://api.github.com/users/ccnokes/following{/other_user}","gists_url":"https://api.github.com/users/ccnokes/gists{/gist_id}","starred_url":"https://api.github.com/users/ccnokes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccnokes/subscriptions","organizations_url":"https://api.github.com/users/ccnokes/orgs","repos_url":"https://api.github.com/users/ccnokes/repos","events_url":"https://api.github.com/users/ccnokes/events{/privacy}","received_events_url":"https://api.github.com/users/ccnokes/received_events","type":"User","site_admin":false},"repo":{"id":52465203,"name":"electron-editor-context-menu","full_name":"ccnokes/electron-editor-context-menu","owner":{"login":"ccnokes","id":1610343,"avatar_url":"https://avatars.githubusercontent.com/u/1610343?v=3","gravatar_id":"","url":"https://api.github.com/users/ccnokes","html_url":"https://github.com/ccnokes","followers_url":"https://api.github.com/users/ccnokes/followers","following_url":"https://api.github.com/users/ccnokes/following{/other_user}","gists_url":"https://api.github.com/users/ccnokes/gists{/gist_id}","starred_url":"https://api.github.com/users/ccnokes/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ccnokes/subscriptions","organizations_url":"https://api.github.com/users/ccnokes/orgs","repos_url":"https://api.github.com/users/ccnokes/repos","events_url":"https://api.github.com/users/ccnokes/events{/privacy}","received_events_url":"https://api.github.com/users/ccnokes/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/ccnokes/electron-editor-context-menu","description":"Enable the native right-click menu in Electron.","fork":true,"url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu","forks_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/forks","keys_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/teams","hooks_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/hooks","issue_events_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/issues/events{/number}","events_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/events","assignees_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/assignees{/user}","branches_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/branches{/branch}","tags_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/tags","blobs_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/git/refs{/sha}","trees_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/statuses/{sha}","languages_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/languages","stargazers_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/stargazers","contributors_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/contributors","subscribers_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/subscribers","subscription_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/subscription","commits_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/commits{/sha}","git_commits_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/git/commits{/sha}","comments_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/comments{/number}","issue_comment_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/issues/comments{/number}","contents_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/contents/{+path}","compare_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/merges","archive_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/downloads","issues_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/issues{/number}","pulls_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/pulls{/number}","milestones_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/milestones{/number}","notifications_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/labels{/name}","releases_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/releases{/id}","deployments_url":"https://api.github.com/repos/ccnokes/electron-editor-context-menu/deployments","created_at":"2016-02-24T18:35:49Z","updated_at":"2016-02-24T18:35:50Z","pushed_at":"2016-12-09T05:51:58Z","git_url":"git://github.com/ccnokes/electron-editor-context-menu.git","ssh_url":"git@github.com:ccnokes/electron-editor-context-menu.git","clone_url":"https://github.com/ccnokes/electron-editor-context-menu.git","svn_url":"https://github.com/ccnokes/electron-editor-context-menu","homepage":null,"size":65,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"mixmaxhq:master","ref":"master","sha":"d1703f7b7e4523af8c9c088d4a1efc06e2dc3b12","user":{"login":"mixmaxhq","id":7530142,"avatar_url":"https://avatars.githubusercontent.com/u/7530142?v=3","gravatar_id":"","url":"https://api.github.com/users/mixmaxhq","html_url":"https://github.com/mixmaxhq","followers_url":"https://api.github.com/users/mixmaxhq/followers","following_url":"https://api.github.com/users/mixmaxhq/following{/other_user}","gists_url":"https://api.github.com/users/mixmaxhq/gists{/gist_id}","starred_url":"https://api.github.com/users/mixmaxhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mixmaxhq/subscriptions","organizations_url":"https://api.github.com/users/mixmaxhq/orgs","repos_url":"https://api.github.com/users/mixmaxhq/repos","events_url":"https://api.github.com/users/mixmaxhq/events{/privacy}","received_events_url":"https://api.github.com/users/mixmaxhq/received_events","type":"Organization","site_admin":false},"repo":{"id":51183535,"name":"electron-editor-context-menu","full_name":"mixmaxhq/electron-editor-context-menu","owner":{"login":"mixmaxhq","id":7530142,"avatar_url":"https://avatars.githubusercontent.com/u/7530142?v=3","gravatar_id":"","url":"https://api.github.com/users/mixmaxhq","html_url":"https://github.com/mixmaxhq","followers_url":"https://api.github.com/users/mixmaxhq/followers","following_url":"https://api.github.com/users/mixmaxhq/following{/other_user}","gists_url":"https://api.github.com/users/mixmaxhq/gists{/gist_id}","starred_url":"https://api.github.com/users/mixmaxhq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mixmaxhq/subscriptions","organizations_url":"https://api.github.com/users/mixmaxhq/orgs","repos_url":"https://api.github.com/users/mixmaxhq/repos","events_url":"https://api.github.com/users/mixmaxhq/events{/privacy}","received_events_url":"https://api.github.com/users/mixmaxhq/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/mixmaxhq/electron-editor-context-menu","description":"Enable the native right-click menu in Electron.","fork":false,"url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu","forks_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/forks","keys_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/teams","hooks_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/hooks","issue_events_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/events{/number}","events_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/events","assignees_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/assignees{/user}","branches_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/branches{/branch}","tags_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/tags","blobs_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/git/refs{/sha}","trees_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/statuses/{sha}","languages_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/languages","stargazers_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/stargazers","contributors_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/contributors","subscribers_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/subscribers","subscription_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/subscription","commits_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/commits{/sha}","git_commits_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/git/commits{/sha}","comments_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/comments{/number}","issue_comment_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/comments{/number}","contents_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/contents/{+path}","compare_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/merges","archive_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/downloads","issues_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues{/number}","pulls_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls{/number}","milestones_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/milestones{/number}","notifications_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/labels{/name}","releases_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/releases{/id}","deployments_url":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/deployments","created_at":"2016-02-06T00:56:10Z","updated_at":"2016-12-02T08:44:15Z","pushed_at":"2016-12-09T06:07:54Z","git_url":"git://github.com/mixmaxhq/electron-editor-context-menu.git","ssh_url":"git@github.com:mixmaxhq/electron-editor-context-menu.git","clone_url":"https://github.com/mixmaxhq/electron-editor-context-menu.git","svn_url":"https://github.com/mixmaxhq/electron-editor-context-menu","homepage":null,"size":61,"stargazers_count":23,"watchers_count":23,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":5,"mirror_url":null,"open_issues_count":3,"forks":5,"open_issues":3,"watchers":23,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6"},"html":{"href":"https://github.com/mixmaxhq/electron-editor-context-menu/pull/6"},"issue":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/6"},"comments":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/issues/6/comments"},"review_comments":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6/comments"},"review_comment":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/pulls/6/commits"},"statuses":{"href":"https://api.github.com/repos/mixmaxhq/electron-editor-context-menu/statuses/2fe9fa68793b4876867a51b5fd3b40b921a9fdcf"}}}}
{"actor":{"display_login":"ccnokes"}}