admin管理员组文章数量:1317909
I'm having an issue with javascript, since chrome v73.0.3683.86, whenever I run my javascript code after window.location.reload() function it always give me the error "Unchecked runtime.lastError: The message port closed before a response was received."
I've searching for many topics over the internet but most of it is about chrome extension. So I tried to run this code in cognito mode and disable all extension but there's no changes.
※For some reason I need to run something after window.location.reload()
onClick javascript function like this
<html>
<head>
<title>Hello world!</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
function buttonClick() {
window.location.reload();
document.title = "Hi there";
}
</script>
</head>
<body>
<div>TODO write content</div>
<button onclick="buttonClick()">Click here</button>
</body>
</html>
I'm having an issue with javascript, since chrome v73.0.3683.86, whenever I run my javascript code after window.location.reload() function it always give me the error "Unchecked runtime.lastError: The message port closed before a response was received."
I've searching for many topics over the internet but most of it is about chrome extension. So I tried to run this code in cognito mode and disable all extension but there's no changes.
※For some reason I need to run something after window.location.reload()
onClick javascript function like this
<html>
<head>
<title>Hello world!</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/javascript">
function buttonClick() {
window.location.reload();
document.title = "Hi there";
}
</script>
</head>
<body>
<div>TODO write content</div>
<button onclick="buttonClick()">Click here</button>
</body>
</html>
Share
Improve this question
asked Apr 3, 2019 at 3:02
nguyen xuan linhnguyen xuan linh
531 gold badge1 silver badge7 bronze badges
9
-
1
For some reason I need to run something after window.location.reload()
- well, your whole design is flawed. Once you reload the page, the code after that is irrelevant – Jaromanda X Commented Apr 3, 2019 at 3:06 -
Oh surprises! @JaromandaX I thought exactly like you and then went to try location.reload();navigator.sendBeacon('foo') on my localhost, and on my server's logs I can clearly see the request is executed. And actually even
location.reload(); localStorage.executesAfter="true";
will work. – Kaiido Commented Apr 3, 2019 at 4:31 - @OP, do you see this message when running the code snippet in your question? 73.0.3683.86 on macOS here, an I got nothing. – Kaiido Commented Apr 3, 2019 at 4:31
- @Kaiido - yes, that works ... but that's not what the OP wants to do, he wants to change the title of the page after unloading it? – Jaromanda X Commented Apr 3, 2019 at 5:16
- Thanks guys, but I'm looking for an explaination about "The message port closed before a response was received" @Jaromanda: Yes, the design is not good, it works well before chrome version 73 though :( – nguyen xuan linh Commented Apr 3, 2019 at 7:32
4 Answers
Reset to default 2Can you try to run it on chrome without any extension? - Right click on your Chrome shortcut - Select Properties. - Add to the end of the Target field --disable-extensions --disable-plugins
It will look like:
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" /high-dpi-support=1 /force-device-scale-factor=1 --disable-extensions --disable-plugins
- Click on OK
- Start Chrome.
Thank guys, I figured out the problem, it's because of an extension try to send message to it's background.js by running "chrome.runtime.sendMessage" Therefore when I run the windown.location.onload() function, it's close the message port and throw out the error message!
The problem is that extension can not be disabled on my office puter :))
Disable all the extensions you installed on the Chrome browser. This worked for me and I saw that many people said it worked.
Hope this works for you too.
If you can't disable the extensions, you can hide the error message in console. Go to console and uncheck the "Errors" under the "Custom levels" right after the Filter. See the screenshot.
Okay this one is a kinda different, not totally related with the problem in the OP. But if you are having a trouble with a button click then here is a reminder.
<button type="button"></button>
This might happen, If you are wrapping the button in a form element. The default behavior of a button inside a form element is "submit". So change it to "button" if the button is not trying to submit formdata.
本文标签:
版权声明:本文标题:google chrome - How to fix "The message port closed before a response was received." after window.location.rel 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742023094a2415044.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论