{"action":"created","issue":{"url":"https://api.github.com/repos/atom/electron/issues/2303","labels_url":"https://api.github.com/repos/atom/electron/issues/2303/labels{/name}","comments_url":"https://api.github.com/repos/atom/electron/issues/2303/comments","events_url":"https://api.github.com/repos/atom/electron/issues/2303/events","html_url":"https://github.com/atom/electron/issues/2303","id":96646302,"number":2303,"title":"Getting \"garbage\" back when using http protocol interception with webview","user":{"login":"alexindigo","id":127063,"avatar_url":"https://avatars.githubusercontent.com/u/127063?v=3","gravatar_id":"","url":"https://api.github.com/users/alexindigo","html_url":"https://github.com/alexindigo","followers_url":"https://api.github.com/users/alexindigo/followers","following_url":"https://api.github.com/users/alexindigo/following{/other_user}","gists_url":"https://api.github.com/users/alexindigo/gists{/gist_id}","starred_url":"https://api.github.com/users/alexindigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexindigo/subscriptions","organizations_url":"https://api.github.com/users/alexindigo/orgs","repos_url":"https://api.github.com/users/alexindigo/repos","events_url":"https://api.github.com/users/alexindigo/events{/privacy}","received_events_url":"https://api.github.com/users/alexindigo/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/atom/electron/labels/bug","name":"bug","color":"fc2929"},{"url":"https://api.github.com/repos/atom/electron/labels/protocol","name":"protocol","color":"f7c6c7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-07-22T19:31:48Z","updated_at":"2015-07-23T04:23:59Z","closed_at":"2015-07-23T04:15:54Z","body":"Trying to intercept `http` protocol and do nothing.\r\n\r\nmain.js:\r\n\r\n```\r\n\r\n// This method will be called when Electron has done everything\r\n// initialization and ready for creating browser windows.\r\napp.on('ready', function()\r\n{\r\n\r\n  // Create the browser window.\r\n  mainWindow = new BrowserWindow({width: 1200, height: 800, frame: true, center: true});\r\n\r\n  // interesting that I can't require protocol module before\r\n  var protocol = require('protocol');\r\n\r\n  protocol.interceptProtocol('http', function(req)\r\n  {\r\n    console.log('\\n\\nGOT HTTP', req.method, req.url, req.referrer, '\\n\\n');\r\n    return null;\r\n  });\r\n\r\n  mainWindow.loadUrl('file://' + __dirname + '/index.html');\r\n``` \r\n\r\nindex.html:\r\n\r\n```\r\n<!DOCTYPE html>\r\n<html>\r\n  <head>\r\n    <title>Loading...</title>\r\n    <script src=\"chrome.js\"></script>\r\n  </head>\r\n  <body>\r\n    <webview class=\"content\"></webview>\r\n  </body>\r\n</html>\r\n```\r\n\r\nchrome.js:\r\n\r\n```\r\nwindow.addEventListener('DOMContentLoaded', function()\r\n{\r\n   var content = document.querySelector('.content');\r\n   content.src = 'http://www.trulia.com';\r\n}, false);\r\n```\r\n\r\nAnd when app is loaded I'd get following in the webview: \r\n![garbage](http://ia.gs/c1ga/Image%202015-07-22%20at%2012.22.46%20PM.png)\r\n\r\nIf there is no protocol intercept page loads normally.\r\n\r\nThank you.\r\n"},"comment":{"url":"https://api.github.com/repos/atom/electron/issues/comments/123959459","html_url":"https://github.com/atom/electron/issues/2303#issuecomment-123959459","issue_url":"https://api.github.com/repos/atom/electron/issues/2303","id":123959459,"user":{"login":"alexindigo","id":127063,"avatar_url":"https://avatars.githubusercontent.com/u/127063?v=3","gravatar_id":"","url":"https://api.github.com/users/alexindigo","html_url":"https://github.com/alexindigo","followers_url":"https://api.github.com/users/alexindigo/followers","following_url":"https://api.github.com/users/alexindigo/following{/other_user}","gists_url":"https://api.github.com/users/alexindigo/gists{/gist_id}","starred_url":"https://api.github.com/users/alexindigo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alexindigo/subscriptions","organizations_url":"https://api.github.com/users/alexindigo/orgs","repos_url":"https://api.github.com/users/alexindigo/repos","events_url":"https://api.github.com/users/alexindigo/events{/privacy}","received_events_url":"https://api.github.com/users/alexindigo/received_events","type":"User","site_admin":false},"created_at":"2015-07-23T04:23:59Z","updated_at":"2015-07-23T04:23:59Z","body":"Funny part is that there is no simple (and non-obtrusive) example, just to see what's going on. :)\r\n\r\nIt took me some time of crawling through issues here to find this syntax :)\r\n\r\n```\r\n protocol.interceptProtocol('http', function(req)\r\n  {\r\n    console.log('\\n\\nGOT HTTP', req.method, req.url, req.referrer, '\\n\\n');\r\n    return null;\r\n  });\r\n```\r\n\r\nAnd I'm still not sure if it's correct. :)\r\n\r\nAnd the fact that I need to require `protocol` module after app is ready (and maybe after MainWindow is created), makes debugging more challenging as well. :)\r\n"}}