RESOLVED FIXED 195834
Can't use $0, $1 etc when inspecting Google Docs pages because the content uses these for function names
https://bugs.webkit.org/show_bug.cgi?id=195834
Summary Can't use $0, $1 etc when inspecting Google Docs pages because the content us...
Simon Fraser (smfr)
Reported 2019-03-15 16:23:17 PDT
Dumping $0, $1 etc in the console when inspecting Google Docs pages dumps some function from the page, rather than the selected element. Can we do something to keep console $ things separate from page $ things?
Attachments
Patch (43.19 KB, patch)
2019-04-27 10:32 PDT, Devin Rousso
no flags
Patch (43.57 KB, patch)
2019-04-27 10:40 PDT, Devin Rousso
no flags
Archive of layout-test-results from ews104 for mac-highsierra-wk2 (2.73 MB, application/zip)
2019-04-27 11:58 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews101 for mac-highsierra (3.08 MB, application/zip)
2019-04-27 13:06 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews114 for mac-highsierra (2.88 MB, application/zip)
2019-04-27 14:44 PDT, EWS Watchlist
no flags
Patch (45.69 KB, patch)
2019-04-27 16:46 PDT, Devin Rousso
no flags
Patch (44.36 KB, patch)
2019-06-25 01:02 PDT, Devin Rousso
no flags
Archive of layout-test-results from ews100 for mac-highsierra (3.32 MB, application/zip)
2019-06-25 01:55 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews104 for mac-highsierra-wk2 (2.75 MB, application/zip)
2019-06-25 02:23 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews115 for mac-highsierra (3.00 MB, application/zip)
2019-06-25 02:53 PDT, EWS Watchlist
no flags
Archive of layout-test-results from ews211 for win-future (13.85 MB, application/zip)
2019-06-25 05:00 PDT, EWS Watchlist
no flags
Patch (50.12 KB, patch)
2019-06-25 09:53 PDT, Devin Rousso
no flags
Patch (52.32 KB, patch)
2019-08-05 16:33 PDT, Devin Rousso
no flags
Patch (52.31 KB, patch)
2019-08-05 16:37 PDT, Devin Rousso
ews-watchlist: commit-queue-
Archive of layout-test-results from ews102 for mac-highsierra (3.48 MB, application/zip)
2019-08-05 17:40 PDT, EWS Watchlist
no flags
Patch (52.33 KB, patch)
2019-08-05 19:20 PDT, Devin Rousso
no flags
Devin Rousso
Comment 1 2019-04-26 15:31:24 PDT
No matter what prefix (e.g. `$`) we pick, there's always a chance that the inspected page (or whatever the current context is) overrides it. A particularly malicious website could decide to blanket create $0...$99 as empty values on `window` to entirely prevent Web Inspector from being able to save values. One idea I had was to create a way for the developer to be able to customize the prefix from the Web Inspector frontend (e.g. an <input> in the Settings tab), so that if they notice that there are already existing values on the page, they could change `$` to be `$sadface` and avoid the collision/shadowing. This would 100% require backend support, but it would be a somewhat easy change to make. The discoverability of this isn't any worse than any other setting, but telling the "story" of this method would be much harder, specifically with the amount of space we traditionally have for any given setting in the Settings tab (e.g. one line with only a few words). I like this approach as it gives the most flexibility to the developer (some people would prefer a different prefix, like `_` or `temp` or `joe`). Alternatively (or in addition to), if we notice that a saved value (e.g. `$1`) would collide with an existing value on the page, we could surface a warning in the console suggesting that the developer change their prefix, or even try to do some smart "expansion" and add as many `_` as needed until there's no collision.
Simon Fraser (smfr)
Comment 2 2019-04-26 15:53:25 PDT
I suggested that if you right-click and "Log Element", inspector finds the first unused $ value that it can, and uses that.
Devin Rousso
Comment 3 2019-04-27 10:32:21 PDT
EWS Watchlist
Comment 4 2019-04-27 10:33:47 PDT Comment hidden (obsolete)
Devin Rousso
Comment 5 2019-04-27 10:40:02 PDT
EWS Watchlist
Comment 6 2019-04-27 11:58:06 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 7 2019-04-27 11:58:08 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 8 2019-04-27 13:06:49 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 9 2019-04-27 13:06:51 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 10 2019-04-27 14:44:57 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 11 2019-04-27 14:44:59 PDT Comment hidden (obsolete)
Devin Rousso
Comment 12 2019-04-27 16:46:51 PDT
Devin Rousso
Comment 13 2019-06-14 18:24:39 PDT
Comment on attachment 368415 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=368415&action=review > Source/WebCore/inspector/CommandLineAPIModuleSource.js:58 > + this.__defineGetter__(prefix("0"), bind(commandLineAPIImpl._inspectedObject, commandLineAPIImpl)); We should probably also have `$0` in addition to the prefixed version for compatibility.
Devin Rousso
Comment 14 2019-06-25 01:02:53 PDT
Created attachment 372824 [details] Patch After talking offline with @JoePeck, we decided that a better course of action is to have the setting be an alias instead, meaning that both the input value and "$" work as a prefix. This way, the existing functionality of "$" is preserved while still providing an alternate way of referencing the values that is less likely to collide with a value in the page.
Devin Rousso
Comment 15 2019-06-25 01:03:53 PDT
Comment on attachment 372824 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372824&action=review > Source/JavaScriptCore/inspector/InjectedScriptSource.js:-1462 > - delete this.$event; Since the command line API is recreated each time something is entered into the Console, there's no need to call `delete` as `this` is a brand new object.
EWS Watchlist
Comment 16 2019-06-25 01:54:58 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 17 2019-06-25 01:55:00 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 18 2019-06-25 02:23:08 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 19 2019-06-25 02:23:10 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 20 2019-06-25 02:53:29 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 21 2019-06-25 02:53:32 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 22 2019-06-25 05:00:09 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 23 2019-06-25 05:00:12 PDT Comment hidden (obsolete)
Devin Rousso
Comment 24 2019-06-25 09:53:52 PDT
Joseph Pecoraro
Comment 25 2019-08-05 13:11:27 PDT
Comment on attachment 372839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372839&action=review r=me > Source/JavaScriptCore/inspector/InjectedScriptSource.js:1459 > + this.$_ = injectedScript._lastResult; I wonder if these should be `__defineGetter__` as well. It doesn't really matter, because they get recreated every evaluation, but I suspect it would throw errors when/if folks try to assign to them. That should have its own test if we make such a change. > Source/JavaScriptCore/inspector/protocol/Runtime.json:322 > + "description": "Creates an additional reference to all saved values in the Console by replacing the default $ prefix with the given string.", This is not `replacing` but providing a parallel prefix. It seems more like a `setSavedResultPrefixAlias` but I'm fine with the existing naming. > Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:334 > + WI.settings.consoleSavedResultAlias.addEventListener(WI.Setting.Event.Changed, updateSavedVariableText); These event handlers need to get removed somewhere, or else they will exist forever on the global Setting. > Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:683 > + WI.settings.consoleSavedResultAlias.addEventListener(WI.Setting.Event.Changed, (event) => { These event handlers need to get removed somewhere, or else they will exist forever on the global Setting. > Source/WebInspectorUI/UserInterface/Views/SettingsTabContentView.js:275 > + consoleSavedResultAliasInput.addEventListener("keydown", (event) => { > + if (!/[a-zA-Z0-9_$]/.test(event.key) || (consoleSavedResultAliasInput.selectionStart === 0 && /[0-9]/.test(event.key))) { > + event.preventDefault(); > + InspectorFrontendHost.beep(); > + } > + }); I guess this validation doesn't need to happen on the backend because this is actually becoming a property, not a variable name. Maybe special case if the final value is "$" it could clear it. > LayoutTests/inspector/runtime/setSavedResultAlias.html:46 > + InspectorTest.newline(); This would totally have made sense as 3 tests instead of just newlines.
Devin Rousso
Comment 26 2019-08-05 15:45:28 PDT
Comment on attachment 372839 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=372839&action=review >> Source/JavaScriptCore/inspector/InjectedScriptSource.js:1459 >> + this.$_ = injectedScript._lastResult; > > I wonder if these should be `__defineGetter__` as well. It doesn't really matter, because they get recreated every evaluation, but I suspect it would throw errors when/if folks try to assign to them. That should have its own test if we make such a change. I like it! >> Source/JavaScriptCore/inspector/protocol/Runtime.json:322 >> + "description": "Creates an additional reference to all saved values in the Console by replacing the default $ prefix with the given string.", > > This is not `replacing` but providing a parallel prefix. It seems more like a `setSavedResultPrefixAlias` but I'm fine with the existing naming. Ah oops. This was from an earlier version. >> Source/WebInspectorUI/UserInterface/Views/ConsoleMessageView.js:334 >> + WI.settings.consoleSavedResultAlias.addEventListener(WI.Setting.Event.Changed, updateSavedVariableText); > > These event handlers need to get removed somewhere, or else they will exist forever on the global Setting. Hmmmm... I'll have to think of a way around this. >> Source/WebInspectorUI/UserInterface/Views/SettingsTabContentView.js:275 >> + }); > > I guess this validation doesn't need to happen on the backend because this is actually becoming a property, not a variable name. > > Maybe special case if the final value is "$" it could clear it. Good call! >> LayoutTests/inspector/runtime/setSavedResultAlias.html:46 >> + InspectorTest.newline(); > > This would totally have made sense as 3 tests instead of just newlines. I'd rather not, as that would mean that each test relies on the state set by the previous test. I prefer keeping test cases completely independent.
Devin Rousso
Comment 27 2019-08-05 16:33:25 PDT
Devin Rousso
Comment 28 2019-08-05 16:37:08 PDT
Created attachment 375582 [details] Patch The placeholder should be "$" to match the default prefix.
EWS Watchlist
Comment 29 2019-08-05 17:40:03 PDT Comment hidden (obsolete)
EWS Watchlist
Comment 30 2019-08-05 17:40:05 PDT Comment hidden (obsolete)
Devin Rousso
Comment 31 2019-08-05 19:20:59 PDT
WebKit Commit Bot
Comment 32 2019-08-05 20:37:50 PDT
Comment on attachment 375594 [details] Patch Clearing flags on attachment: 375594 Committed r248287: <https://trac.webkit.org/changeset/248287>
WebKit Commit Bot
Comment 33 2019-08-05 20:37:53 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 34 2019-08-05 20:38:35 PDT
Note You need to log in before you can comment on or make changes to this bug.