views:

344

answers:

3

Is it possible to fork a users session (or do something similar) in a Internet Explorer plugin?

I want to process the page the user is on when they click a button in the toolbar. To avoid interrupting the users browsing, I'd like to "copy" everything so I can parse and process the page in the background. The processing can involve things such as loading the content of the result links on a Google search, if that's where the button was clicked.

So - what I basically want is to imitate "Ctrl+N" but hide the window from the user, so they won't be interrupted.

As you can see, if you fill out and submit the form on http://www.snee.com/xml/crud/posttest.html and press "Ctrl+N", everything posted will still appear in the new window, but it won't post the data twice.

I was thinking of somehow copying the IWebBrowser2, but:

  • I'm not sure if that's possible (I haven't been able to find any information on MSDN)
  • I don't know if it copies the sessions as well.

Creating a new instance of the IWebBrowser2 and simply navigating to the current URL isn't a valid solution as POST-variables of course doesn't get carried over.

A: 

Interesting thought. Could you copy the DOM holus-bolus and then replace a new window's DOM with the copy. It's just a guess. I'm as much in the dark as you at this point.

boost
A: 

A BHO or plugin would work. There are so many options to get the source, it's kinda. pick your poising. Look up IDocHostUIHandler to alter behaviour. IHTMLElementCollection to parse the page in browser. The easiest thing I can think of at the moment is....

Save the current contents to a stream. same as get/view source.

// #include 
HRESULT SaveDocumenttoStream(IWebBrowser* pWebBrowser, 
                             IStream* pStream)
{
HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;
hr = pWebBrowser->get_Document( &pHtmlDoc );
if ( SUCCEEDED(hr) && pHtmlDoc)
{
  // Query for IPersistStreamInit.
  hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,
                               (void**)&pPersistStreamInit );
  if ( SUCCEEDED(hr) )
  { 
     hr = pPersistStreamIni->Save(, True);
     pPersistStreamInit->Release(); 
  }
  pHtmlDoc->Release();
}

You supply the browser and stream.HTH

--

Michael

Michael
A: 

I think it is impossible to do because you have to think about so many details, something will always break. Just to mention two:

  • You have to take care of embedded web browsers (frames, IFRAMEs). I think copying the main page would just copy their URLs so their content will be reloaded when you restore the serialized main page somewhere, thus the content of your page changes. So you would have to go down to the frame level.
  • You would have to take care about scripts which behind your back try to connect to some server to send data which has already been sent by the page you forked. So you might change the logic of the page.

So processing live is the only true solution to capture the state as the users sees it; if this is what you want to achieve. If you don't need so much detail it might be easier to do.

Heinrich Ulbricht