{"action":"created","issue":{"url":"https://api.github.com/repos/atom/electron/issues/4444","repository_url":"https://api.github.com/repos/atom/electron","labels_url":"https://api.github.com/repos/atom/electron/issues/4444/labels{/name}","comments_url":"https://api.github.com/repos/atom/electron/issues/4444/comments","events_url":"https://api.github.com/repos/atom/electron/issues/4444/events","html_url":"https://github.com/atom/electron/issues/4444","id":133019315,"number":4444,"title":"interceptBufferProtocol but fallback to default","user":{"login":"mattdesl","id":1383811,"avatar_url":"https://avatars.githubusercontent.com/u/1383811?v=3","gravatar_id":"","url":"https://api.github.com/users/mattdesl","html_url":"https://github.com/mattdesl","followers_url":"https://api.github.com/users/mattdesl/followers","following_url":"https://api.github.com/users/mattdesl/following{/other_user}","gists_url":"https://api.github.com/users/mattdesl/gists{/gist_id}","starred_url":"https://api.github.com/users/mattdesl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mattdesl/subscriptions","organizations_url":"https://api.github.com/users/mattdesl/orgs","repos_url":"https://api.github.com/users/mattdesl/repos","events_url":"https://api.github.com/users/mattdesl/events{/privacy}","received_events_url":"https://api.github.com/users/mattdesl/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-02-11T16:23:56Z","updated_at":"2016-02-14T21:10:19Z","closed_at":null,"body":"Hey there!\r\n\r\nI'm trying to intercept `'file'` protocol so that a different `index.html` is served depending on some variables. I currently have something like this:\r\n\r\n```js\r\n  var url = 'file://' + __dirname + '/index.html';\r\n\r\n  // Replace index.html with custom one\r\n  electron.protocol.interceptBufferProtocol('file', function (request, callback) {\r\n    if (request.url === url) {\r\n      callback({\r\n        data: customHTML,\r\n        mimeType: 'text/html'\r\n      });\r\n    } else {\r\n      // ... Fall back to default??\r\n    }\r\n  }, function (err) {\r\n    if (err) throw err;\r\n  });\r\n```\r\n\r\nHowever, this breaks browser features like `Image` and other media (audio/video). I can add a custom `fs.readFile` and send the result to `callback({ data, mimeType })`, which works with `image.onload`, but errors are not handled as they should be by the browser and `image.onerror` won't get called.\r\n\r\nIs there another approach to replacing the HTML dynamically from `file://` protocol? Or a way to fall back to default protocol behaviour? Or some means of only targeting a specific URL?"},"comment":{"url":"https://api.github.com/repos/atom/electron/issues/comments/183977543","html_url":"https://github.com/atom/electron/issues/4444#issuecomment-183977543","issue_url":"https://api.github.com/repos/atom/electron/issues/4444","id":183977543,"user":{"login":"deepak1556","id":964386,"avatar_url":"https://avatars.githubusercontent.com/u/964386?v=3","gravatar_id":"","url":"https://api.github.com/users/deepak1556","html_url":"https://github.com/deepak1556","followers_url":"https://api.github.com/users/deepak1556/followers","following_url":"https://api.github.com/users/deepak1556/following{/other_user}","gists_url":"https://api.github.com/users/deepak1556/gists{/gist_id}","starred_url":"https://api.github.com/users/deepak1556/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/deepak1556/subscriptions","organizations_url":"https://api.github.com/users/deepak1556/orgs","repos_url":"https://api.github.com/users/deepak1556/repos","events_url":"https://api.github.com/users/deepak1556/events{/privacy}","received_events_url":"https://api.github.com/users/deepak1556/received_events","type":"User","site_admin":false},"created_at":"2016-02-14T21:10:19Z","updated_at":"2016-02-14T21:10:19Z","body":"Invoking callback with chromium net_err_codes does call onerror event handler. But if you are just serving local files why not use `interceptFileProtocol` ?"}}