question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

functions called from browser execute twice

See original GitHub issue

Although curl will only call the function once. Chrome load or refresh calls the function twice. A bit confusing when debugging something more complex than HelloWorld.

Very easy to see:

exports.helloWorld = (req, res) => {
    console.log('running HelloWorld'); // <-- oh no not again
    res.send('Hello, World');
  };

Is there a way to stop this?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:14 (7 by maintainers)

github_iconTop GitHub Comments

5reactions
stew-rcommented, May 29, 2019

OK so we think this is happening because browser requests also send a request for a favicon. This means that hitting the function in the browser results in two invocations of the function.

I think we can fix this by changing our logic to only invoke the function in response to requests on /${function_name} instead of /*.

Thanks for the report.

1reaction
Didier68commented, Jul 27, 2020

Hello, I have the same problem, but I do not understand the answers speaking the link with favicon: in the second call, I find in “req.url” the same path as in the first call. This bug becomes annoying as soon as I dedug the Node server, because I’m juggling between 2 threads which do the same things in parallel.

Does anyone know how to block this in Chrome?

Read more comments on GitHub >

github_iconTop Results From Across the Web

functions called from browser execute twice · Issue #33 - GitHub
Chrome load or refresh calls the function twice. A bit confusing when debugging something more complex than HelloWorld. Very easy to see:.
Read more >
function is being executed twice when called only once
Your browser is making two requests to your server, most likely one for the URL you put in the address bar and another...
Read more >
Content Script Executing Twice? - Mozilla Discourse
js, you execute the script again using browser.tabs.executeScript, which causes the second execution. Nothing wrong with Firefox here.
Read more >
QGIS plugin triggers function twice - GIS Stack Exchange
I have a plugin with a function (triggered by a button) that selects a specific layer by name, then shows its attribute table....
Read more >
Function called twice javascript
The basic idea is to set a timeout to call the function after a certain time (half second here, depends on the execution...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found