I have a content-script extension that requests character information
from
wowarmory.com (a World of Warcraft oriented website), and embeds
it into another website.
wowarmory.com is using XSLT to serve its
pages.
My Chrome extension was ported through a GreaseMonkey script for
Firefox. The GM content-script uses GM_xmlhttprequest method to handle
cross-origin XHR. In Chrome I have my content-script using sendRequest
and background.html listening for onRequest, then handling
XMLHttpRequest.
The problem is these two methods return different results for unknown
reasons.
Grease Monkey script: Without sending any additional headers, the
response.responseText is an XML formatted document.
response.responseXML is null, for some reason. Unimportant, as I use
DOMParser().parseFromString() to make the responseText an XML object.
Chrome script: Without sending any additional headers, the
response.responseText is an HTML formatted document.
response.responseXML is null. This is a problem. I can't make an XML
object out of HTML text. Why did Chrome return HTML text but GM
returned XML text?
In my Chrome extension I tried setting the User-Agent header:
xhr.setResponseHeader('User-Agent', 'Mozilla/5.0 (Windows; U; Windows
NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/
2.0.0.1')
However, response.responseText still returned HTML text.
An older or invalid user-agent would have
wowarmory.com respond w/HTML
to ensure compatibility, whereas an XSLT compatible browser has
wowarmory.com respond w/XML. In theory I shouldn't have to set User-
Agent, the extension is running in Chrome. Spoofing the User-Agent is
only necessary when there's no browser environment (e.g. a request
made by a PHP script).
In short: I can't seem to get XML text from my Chrome extension using
XMLHttpRequest (either XML formatted text from responseText or an
actual XML document from responseXML), but my Grease Monkey script
gets XML formatted text without problem.
Any thoughts?
--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to
chromium-...@chromium.org.
To unsubscribe from this group, send email to
chromium-extens...@chromium.org.
For more options, visit this group at
http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.