-
Notifications
You must be signed in to change notification settings - Fork 71
Handle 404 from External Resources #32
Comments
Perhaps, you could use a client-side technology (like JavaScript) to avoid this behavior. |
Care to elaborate? What event would I listen to or what selector would I use to find image URLs that returned a 404? Would I do this on document ready? Would Shrimp and Phantom wait for my JS to finish executing on document ready? |
Would be excellent if I could somehow pass an error handler to PhantomJS: I'm not sure what the limitations would be for that. Impossible to pass a JS function from Shrimp to PhantomJS? Maybe CoffeeScript or Opal.rb would help? |
Attempted to use jQuery error handling techniques: That page provides an example exactly for this situation - except without the context of PDF generation. However, I cannot see a way to prevent the error event from actually triggering. I believe that is what causes a |
I came across a similar issue with broken images @sealocal . while using phantomjs 2.0 I found that the problem is in rasterize.js:52
perhaps you don't kill the rendering if there is a 404 on the page? We already know there isn't an error from loading the page in the previous method:
For a short term fix I just downgraded to 0.0.2 and it worked. Another work-around is to just have a return on that line.
|
Thanks, @nathanbrakken! Would the maintainers, @adjust, be interested in a PR with that fix? It seems like this is the kind of thing that should be accessible as a
|
@sealocal I'm not sure that it would work to have as a config.json option. I would suggest removing the onResourceError method from the js file altogether. Is there any benefit of a hard fail if there is a missing resource on the page? |
@nathanbrakken I don't really know that it has a technical benefit, but someone put it there thinking that it was a good idea. Perhaps they had a good reason for it. I figure that if someone else wants the error raised onResourceError, and I want it to not be raised, then the only middle ground is an option for the behavior. |
I'm trying to create a PDF from a URL that produces an HTML document that looks like the one below.
http://www.example.com/foo/bar/baz.png
is a path to an image that does not exist.to_pdf
fails for the URL that points to this HTML page. How would I go about generating a PDF with some placeholder like a "broken image" or an "X" icon like a modern browser would display? Or how would I display the alt text instead?The text was updated successfully, but these errors were encountered: