-1

I'm creating a chrome extension for Facebook that runs a script in the page. Facebook in its normal operation sometimes shows the following message in the Chrome console (with red):

kZLAjcLHBWC.js:26 GET https://www.facebook.com/ufi/reaction/profile/browser/fetch/?limit=50&shown…=o&__req=9w&__be=-1&__pc=PHASED%3ADEFAULT&__rev=2661965&__srp_t=1478186873 400 ()

I want to create any js function that will determine when this event is happening (the 400 GET error).

CristianC
  • 303
  • 3
  • 11
  • You should specify where those errors come from. Your code? You should include it. Some third-party code? You need to explain that. – Xan Nov 03 '16 at 12:33
  • Please [edit] the question to be on-topic: include a **complete** [mcve] that duplicates the problem. Usually, including a *manifest.json*, some of the background *and* content scripts. Questions seeking debugging help ("**why isn't this code working?**") must include: ►the desired behavior, ►a specific problem or error *and* ►the shortest code necessary to reproduce it **in the question itself**. Questions without a clear problem statement are not useful to other readers. See: "**How to create a [mcve]**", [What topics can I ask about here?](http://stackoverflow.com/help/on-topic), and [ask]. – Makyen Nov 03 '16 at 13:19
  • Ok, in order to make it more clear: I want to make simple function that captures this behaviour which shows in the console: `kZLAjcLHBWC.js:26 GET https://www.facebook.com/ufi/reaction/profile/browser/fetch/?limit=50&shown…=o&__req=9w&__be=-1&__pc=PHASED%3ADEFAULT&__rev=2661965&__srp_t=1478186873 400 ()` The 400 GET error is not caused by my script. I only want to capture it with my script. – CristianC Nov 03 '16 at 15:38
  • What's the purpose of the (hypothetical) handler of this event? How is your code going to react? – Xan Nov 03 '16 at 15:49
  • The extension clicks on a button multiple times, up until Facebook starts sending only these error messages and stops the normal behaviour. At this point I want the extension to stop clicking on the button. – CristianC Nov 03 '16 at 15:53

1 Answers1

0

It's going to be challenging to catch from a content script; since it's not a JS error that bubbles up, it has to be caught in the page's own code, and there are barriers to that. They can be overcome, but then you're operating in the possibly hostile environment of the page's code.

An alternative is to use webRequest API, specifically chrome.webRequest.onErrorOccurred event. This will allow you to detect errors on specific requests.

However, this can't be done from a content script. You'd need a background script that messages the content script when the event happens.

Xan
  • 74,770
  • 16
  • 179
  • 206