Chrome run JavaScript code from the previous page load
Reported by
zayan...@gmail.com,
Apr 21 2017
|
|||||||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.81 Safari/537.36
Steps to reproduce the problem:
Run a page with the following code (tested on localhost)
<script>
console.log("first line of code");
var runCounter = parseInt(localStorage.getItem("runCounter") || 1);
console.log("Run #" + runCounter);
/* you can change the console.error below with any function
like alert and it would run before the first line in the next refresh */
setTimeout(() => console.error("err from run #" + runCounter), 1);
localStorage.setItem("runCounter", runCounter + 1);
if (runCounter % 2) //stop page from refresh loop
window.location.reload();
</script>
What is the expected behavior?
The console shouldn't print any thing before the "first line of code"
What went wrong?
Code from the previous page load run when the page is refreshed before the first line of code is got to run
Note that preserve log is disabled in my Chrome and it's not an issue with just console functions as any function or code like alert will also run before the first line from the previous page load if it was async/queued function like in setTimeout(fn,1)
Did this work before? N/A
Chrome version: 58.0.3029.81 Channel: stable
OS Version: 10.0
Flash Version:
,
Apr 24 2017
When I set the timeout to 1000, I do not see it. From that, I think the problem is not about execution of JavaScript but the timing dev console clears the output. Please feel free to re-label if the observation does not seem correct.
,
Apr 24 2017
,
Apr 24 2017
,
Apr 28 2017
Not sure whether this is a bug. Reload doesn't happen instantly, and setTimeout was being able to execute before that. Changing timeout to 1000 means it's not run before reload happens.
,
Jun 3 2017
Don't we clear console upon commit? In this case, we should not see the previous run messages.
,
Jun 12 2017
We do clear on frameStartedLoading, but that log happens afterwards. In theory, we could clear console on global object cleared event, I'll try that.
,
Jun 14 2017
The following revision refers to this bug: https://chromium.googlesource.com/chromium/src.git/+/1ba21006d3c29454dc12c3b6c3b011137d9159f4 commit 1ba21006d3c29454dc12c3b6c3b011137d9159f4 Author: dgozman <dgozman@chromium.org> Date: Wed Jun 14 22:12:08 2017 [DevTools] Clear console on GlobalObjectCleared Previously we did it on MainFrameStaredLoading instead, but that is too early. BUG= 714292 Review-Url: https://codereview.chromium.org/2939503002 Cr-Commit-Position: refs/heads/master@{#479520} [modify] https://crrev.com/1ba21006d3c29454dc12c3b6c3b011137d9159f4/third_party/WebKit/Source/devtools/front_end/console_model/ConsoleModel.js [modify] https://crrev.com/1ba21006d3c29454dc12c3b6c3b011137d9159f4/third_party/WebKit/Source/devtools/front_end/sdk/ResourceTreeModel.js
,
Jun 19 2017
|
|||||||
►
Sign in to add a comment |
|||||||
Comment 1 by nyerramilli@chromium.org
, Apr 24 2017