Index: go-back-with-backspace/content_script.js |
diff --git a/go-back-with-backspace/content_script.js b/go-back-with-backspace/content_script.js |
index 32fff927f8e80fe94fee0fc0c711ce42554a484f..ea6cecb9faed2c4f69ea92af858ad7961f53eac5 100644 |
--- a/go-back-with-backspace/content_script.js |
+++ b/go-back-with-backspace/content_script.js |
@@ -1,11 +1,17 @@ |
// Listen for shift-backspace or unmodified backspace and navigate if not in |
-// an editable field. |
-document.addEventListener('keydown', function(e) { |
+// an editable field. We capture the event at the Window to let any handlers |
+// or listeners registered on the Document have a chance to handle it first. |
+window.addEventListener('keydown', function(e) { |
+ // Listening on the Window means the event has no path (see |
+ // http://crbug.com/645527), so we'll have to look at the focused (active) |
+ // element. This means it will not work properly with shadow DOM. |
+ // TODO: Fix behavior with shadow DOM when the above bug is resolved. |
if (e.key === 'Backspace' && |
+ !e.defaultPrevented && |
!e.altKey && |
!e.ctrlKey && |
!e.metaKey && |
- !isEditable(e.path)) { |
+ !isEditable(document.activeElement)) { |
e.shiftKey ? window.history.forward(): window.history.back(); |
e.preventDefault(); |
} |