Oliver Nassar

I can be reached at onassar@gmail.com.

For my open source work, check out github.com/onassar


new Image() in Chrome doesn't include referrer header

View more posts

Ran into a weird bug after IMDB presumably did an update to the way their static content is served.

When pinging an image from JS via the Image object, Chrome seems to exclude the referrer header, where as Firefox includes it. The result?

Well depending on how the server you're hitting is configured, you might get rejected (or in my case, a 403). I ran into this problem with my page scraper. I have a link tool on this site whereby I throw in a link, and it scrapes the content, including the open-graph meta tags found in the source.

I was grabbing the open-graph meta tag og:image so that I could grab an image off the site. In order to do this, I make a call via ajax which hits my PHP backend. It then scrapes the page, and returns the value of the og:image tag. To ensure that it's a valid image, however, I load it on the client-side via a new Image() statement. This lets met check the width/height of the presumed image, ensuring that it's legit.

It loads beautifully in Chrome like it always did, but in Firefox, which is sending along a referrer header, it doesn't. I'm guessing Amazon/IMDB is doing this to prevent people like me from scraping their content (although I don't think I'm doing it in a malicious-way at all).

Odder-still is that Facebook is doing the same thing, and it still seems to work there. I'm guessing they have an exception set up for them (boo).