Skip to content

Commit 3aaa6a2

Browse files
thomsbgbenvinegar
authored andcommitted
Record input breadcrumbs from contentEditable targets (#748)
* Record input events from contentEditable targets * Add an integration test for contenteditable breadcrumbs
1 parent 3671931 commit 3aaa6a2

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/raven.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -742,7 +742,7 @@ Raven.prototype = {
742742
// only consider keypress events on actual input elements
743743
// this will disregard keypresses targeting body (e.g. tabbing
744744
// through elements, hotkeys, etc)
745-
if (!tagName || tagName !== 'INPUT' && tagName !== 'TEXTAREA')
745+
if (!tagName || tagName !== 'INPUT' && tagName !== 'TEXTAREA' && !target.isContentEditable)
746746
return;
747747

748748
// record first keypress in a series, but ignore subsequent

test/integration/frame.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
<!-- test element for breadcrumbs -->
7979
<form id="foo-form">
8080
<input name="foo" placeholder="lol"/>
81+
<div class="contenteditable" contenteditable="true"></div>
8182
</form>
8283

8384
<div class="c">

test/integration/test.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -735,6 +735,39 @@ describe('integration', function () {
735735
);
736736
});
737737

738+
it('should record consecutive keypress events in a contenteditable into a single "input" breadcrumb', function (done) {
739+
var iframe = this.iframe;
740+
741+
iframeExecute(iframe, done,
742+
function () {
743+
setTimeout(done);
744+
745+
// some browsers trigger onpopstate for load / reset breadcrumb state
746+
Raven._breadcrumbs = [];
747+
748+
// keypress <input/> twice
749+
var keypress1 = document.createEvent('KeyboardEvent');
750+
keypress1.initKeyboardEvent("keypress", true, true, window, "b", 66, 0, "", false);
751+
752+
var keypress2 = document.createEvent('KeyboardEvent');
753+
keypress2.initKeyboardEvent("keypress", true, true, window, "a", 65, 0, "", false);
754+
755+
var div = document.querySelector('[contenteditable]');
756+
div.dispatchEvent(keypress1);
757+
div.dispatchEvent(keypress2);
758+
},
759+
function () {
760+
var Raven = iframe.contentWindow.Raven,
761+
breadcrumbs = Raven._breadcrumbs;
762+
763+
assert.equal(breadcrumbs.length, 1);
764+
765+
assert.equal(breadcrumbs[0].category, 'ui.input');
766+
assert.equal(breadcrumbs[0].message, 'body > form#foo-form > div.contenteditable');
767+
}
768+
);
769+
});
770+
738771
it('should record history.[pushState|back] changes as navigation breadcrumbs', function (done) {
739772
var iframe = this.iframe;
740773

0 commit comments

Comments
 (0)