FIX: use correct iframe selector and defer init until Docs is ready#17
Open
bennidhamma wants to merge 1 commit into
Open
FIX: use correct iframe selector and defer init until Docs is ready#17bennidhamma wants to merge 1 commit into
bennidhamma wants to merge 1 commit into
Conversation
The extension was attaching the keydown listener to the wrong iframe —
getElementsByTagName('iframe')[0] returns the first iframe in DOM order,
which is not the text event target. page_script.js already used the correct
.docs-texteventtarget-iframe selector; content.js now matches it.
Additionally, Google Docs injects its iframes dynamically after document_idle,
so a MutationObserver is used to defer initialization until the target iframe
exists. cursorTop is also fetched lazily for the same reason.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The extension shows the NORMAL mode indicator but keystrokes are not intercepted — text inserts as if in insert mode.
Two bugs cause this:
Wrong iframe:
content.jsusedgetElementsByTagName('iframe')[0], which returns the first iframe in DOM order. Google Docs has multiple iframes; the text event target is.docs-texteventtarget-iframe. The keydown listener was attached to the wrong element, so keystrokes were never intercepted. (page_script.jsalready used the correct selector — this bringscontent.jsin line with it.)Timing race: Google Docs injects its iframes dynamically after
document_idle. Even with the correct selector, the element may not exist when the content script runs. AMutationObservernow defers initialization until the target iframe appears.cursorTop(.kix-cursor-top) is fetched lazily for the same reason.Changes
getElementsByTagName('iframe')[0]withdocument.querySelector('.docs-texteventtarget-iframe')MutationObserverretries until it iscursorToplazily inswitchModeToNormal/switchModeToInsertwith a null guardTest plan
ito enter insert mode, type text, pressEscape— returns to NORMAL and keystrokes are intercepted again