Skip to content
This repository has been archived by the owner on May 30, 2023. It is now read-only.

Suppress reporting of javascript errors #10042

Closed
ariya opened this issue Feb 19, 2011 · 14 comments
Closed

Suppress reporting of javascript errors #10042

ariya opened this issue Feb 19, 2011 · 14 comments
Assignees

Comments

@ariya
Copy link
Owner

ariya commented Feb 19, 2011

vbcam....@gmail.com commented:

What steps will reproduce the problem?

  1. load a page that throws a javascript error
  2. observe that phantomjs outputs the errors to the console

What is the expected output? What do you see instead?
Some pages have javascript errors for no good reason, but I still need to process html and output data to the console, but there are javascript errors inserted before my output, which fouls up the output with javascript errors that we can't mute.

What version of the product are you using? On what operating system?
1.0, windows server 2003

Please provide any additional information below.
Would like a flag to suppress javascript errors from being reported to the console output.

Disclaimer:
This issue was migrated on 2013-03-15 from the project's former issue tracker on Google Code, Issue #42.
🌟   3 people had starred this issue at the time of migration.

@ariya
Copy link
Owner Author

ariya commented Feb 20, 2011

ariya.hi...@gmail.com commented:

This is probably solved with http://code.google.com/p/phantomjs/issues/detail?id=12.

@ariya
Copy link
Owner Author

ariya commented Feb 21, 2011

ariya.hi...@gmail.com commented:

Maybe like a command line option --quiet?

 
Metadata Updates

  • Label(s) added:
    • Component-Logic
  • Milestone updated: Release1.1 (was: ---)

@ariya
Copy link
Owner Author

ariya commented Feb 21, 2011

ariya.hi...@gmail.com commented:

 

 
Metadata Updates

@ariya
Copy link
Owner Author

ariya commented Feb 21, 2011

ariya.hi...@gmail.com commented:

 

 
Metadata Updates

  • Title updated: Suppress reporting of javascript errors

@ariya
Copy link
Owner Author

ariya commented Mar 14, 2011

ariya.hi...@gmail.com commented:

A simple way to reproduce this:

phantomjs examples/loadspeed.js http://google.com/m/gp

which somehow always spits the error:

Loading http://google.com/m/gp
http://www.google.com/m/gp:14 TypeError: Result of expression 'document.write' [undefined] is not a function.
Page title is Google
Loading time 801 msec

@ariya
Copy link
Owner Author

ariya commented Mar 14, 2011

ariya.hi...@gmail.com commented:

Looks like it's pretty challenging to change how this would be handled differently. Apparently thrown exception makes it to the console output via QWebPage::javaScriptConsoleMessage.

I believe the only way we can override it is when we tweak QtWebKit by hand (issue 31).

 
Metadata Updates

@ariya
Copy link
Owner Author

ariya commented Mar 18, 2011

vbcam....@gmail.com commented:

my workaround for this is to write a delimiter when my code starts running, so if there are any page errors, and i need the output from the console, i can easily strip out the page errors that can't be suppressed. worked well enough for me to get the job done.

@ariya
Copy link
Owner Author

ariya commented May 17, 2011

Genotip7@gmail.com commented:

Why not to use stderr to write errors (and also console.warn, console.error)?

@ariya
Copy link
Owner Author

ariya commented May 17, 2011

ariya.hi...@gmail.com commented:

@Genotip7: This is not a question of implementation. We currently can't do that due to the limitation in QtWebKit API (and hence comment #5).

@ariya
Copy link
Owner Author

ariya commented Jun 2, 2011

ariya.hi...@gmail.com commented:

Should be solved with issue 12.

@ariya
Copy link
Owner Author

ariya commented Jun 6, 2011

ariya.hi...@gmail.com commented:

This should be fixed now. See issue 12.

 
Metadata Updates

  • Status updated: Fixed

@ariya ariya closed this as completed Jun 6, 2011
@ghost ghost assigned ariya Mar 15, 2013
@JustJeremy
Copy link

Hello, any movement on this? I am having the same problem. I scrape quite a few pages but there are js errors on those pages. The errors have no effect on what I'm grabbing however the error outputs to my return array and really hoses things up. This pretty much kills my ability to use this. I'm using the latest version of PJS.

@zackw
Copy link
Contributor

zackw commented Apr 23, 2015

@JerWegener You can suppress all of that, you just have to write some code to do it, and it's a little more complicated than it would ideally be:

  1. Define callback functions for page.onConsoleMessage, page.onError, page.onAlert, page.onConfirm, and page.onPrompt that suppress the output. (The first three can just do nothing, but onConfirm needs to return true and onPrompt needs to return a string.)
  2. Use page.onPageCreated to apply the same callback functions to any pages that get created by window.open or similar.

For a complete worked example see https://github.com/zackw/tbbscraper/blob/master/scripts/pj-trace-redir.js (which does a lot of other stuff -- look for p_onConsoleMessage and p_onPageCreated).

@JustJeremy
Copy link

@zackw Wow thanks for the quick reply on this. I will check it out and see how to integrate that into my scripts.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants