This is a super weird bug…
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-midres-replacement", "onload", "class", "id", "data-a-image-name", "data-a-hires"]
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-hires-replacement", "onload", "data-a-image-name", "class", "id", "data-a-dynamic-image", "style"]
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-hires-replacement", "onload", "data-a-image-name", "class", "id", "data-a-dynamic-image", "style"]
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-hires-replacement", "onload", "data-a-image-name", "class", "id", "data-a-dynamic-image", "style"]
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-hires-replacement", "onload", "data-a-image-name", "class", "id", "data-a-dynamic-image", "style"]
(byebug) Nokogiri::HTML(open(url, {read_timeout: timeout}.merge(http_params)).read).css("#main-image").first.attributes.keys
["alt", "src", "data-fling-asin", "data-fling-refmarker", "data-midres-replacement", "onload", "class", "id", "data-a-image-name", "data-a-hires"]
(byebug)
For some reason, the attributes in the image keeps changing. Note how it alternates between [data-a-hires, data-hires-replacement]
and [data-a-dynamic-image, data-midres-replacement]
Why? I’m not sure and I’ve spent too much time trying to figure out why. I did manage to reproduce the different image tag attributes in my browser by loading the same product URL normally and in incognito mode.
I’ll wait a day or two before merging my PR below to see if anyone might know why…
https://github.com/discourse/onebox/pull/318