vijayfromzukmo
vijayfromzukmo

Reputation: 1

Unable to get the document object for the main page of certain sites in Opera

We are building an opera extension in which we are trying to use the document object property (document.body.innerHTML) in order to obtain the source of the main page of a site. In most cases it provides us with the correct page source but for certain sites (ones that have multiple document layers), it doesn't return the top most document.

For instance, for the site (https://www.pcisecuritystandards.org/) we would like to source for the main page that is displayed but once the entire page is loaded, the document property would display the source for another layer (https://s7.addthis.com/static/r07/sh29.html#cb=0&ab=-&dh=www.pcisecuritystandards.org&dr=&du=https%3A%2F%2Fwww.pcisecuritystandards.org%2F&dt=Official%20PCI%20Security%20Standards%20Council%20Site%20-%20Verify%20PCI%20Compliance%2C%20Download%20Data%20Security%20and%20Credit%20Card%20Security%20Standards&inst=1&lng=en&pc=men&pub=&ssl=1&sid=4d2ee1f94278e71b&srd=1&srf=0.02&srp=0.2&srx=0&ver=250&xck=0&rev=86981&xd=1)

This perhaps has to do with how opera loads the document layers in a page. We did not face any issue with any other browser

How can we obtain the source of the main page (https://www.pcisecuritystandards.org/) using the document object in Opera ?

Upvotes: 0

Views: 522

Answers (3)

vijayfromzukmo
vijayfromzukmo

Reputation: 1

We had checked and found that in case of opera, we are not obtaining reference to the top most document object no matter what document or window property we tried to use. In fact We had tried using window.top and window.parent but nothing seemed to provide a handle on the window object and these properties returned null.

Regarding this "Injected scripts will get injected into the top document as well as any iframe on the page", we got an alert (which we included in the injected script) only from the iFrame but not from the top most window. we found what you said to be true only in Google Chrome and Safari.

Upvotes: 0

miketaylr
miketaylr

Reputation: 1976

It looks like you're possibly in an <iframe>. Injected scripts will get injected into the top document as well as any iframe on the page, so just do a check that you're in the top-most window before grabbing the innerHTML. Something like if (window.self == window.top).

Upvotes: 1

karlcow
karlcow

Reputation: 6972

Did you try to use dragonfly it is useful to understand what is happening with Opera. Right now I'm using Opera 11 and when I go to the page you mentionned. I got a few things in innerHTML.

"<div style="visibility: hidden; height: 1px; width: 1px; position: absolute; z-index: 100000" id="_atssh"><iframe id="_atssh827" style="height: 1px; width: 1px; position: absolute; z-index: 100000; border-top-color: currentColor; border-left-color: currentColor; border-right-color: currentColor; border-bottom-color: currentColor; border-top-width: 0px; border-left-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-top-style: none; border-left-style: none; border-right-style: none; border-bottom-style: none; left: 0px; top: 0px" src="//s7.addthis.com/static/r07/sh30.html#cb=0&amp;ab=-&amp;dh=www.pcisecuritystandards.org&amp;dr=&amp;du=https%3A%2F%2Fwww.pcisecuritystandards.org%2F&amp;dt=Official%20PCI%20Security%20Standards%20Council%20Site%20-%20Verify%20PCI%20Compliance%2C%20Download%20Data%20Security%20and%20Credit%20Card%20Security%20Standards&amp;inst=1&amp;lng=fr&amp;pc=men&amp;pub=&amp;ssl=1&amp;sid=4d358407b896251f&amp;srd=1&amp;srf=0.02&amp;srp=0.2&amp;srx=0&amp;ver=250&amp;xck=0&amp;rev=88088&amp;xd=1"></iframe></div>
    <a name="top" id="top"></a>
    <div id="container">
      <a name="index" id="index"></a>
[…etc]

<h2>NEWS</h2>

So we can see the news section so I get back indeed the home page. Note that some markup has been injected through scripts. Could you paste the piece of code you are using.

Upvotes: 0

Related Questions