NewWindow capture and download

112 views
Skip to first unread message

Bob Frankston

unread,
Aug 13, 2015, 11:52:50 PM8/13/15
to CefSharp

Is there a way to handle the creation of a new window? In this case I want to handle a new window created to display PDF file - i want to handle that window and also force a download of the PDF.

Bob Frankston

unread,
Aug 14, 2015, 12:14:55 PM8/14/15
to CefSharp
Upon further checking this may be partially handled as "Popups" in 43.x -- still learning. Next will need to tackle getting PDFs to always download rather than display.

Alex Maitland

unread,
Aug 14, 2015, 7:54:40 PM8/14/15
to CefSharp
What exactly do you mean by handle the window? Can you elaborate on your questions in general, they're a little vague.

Bob Frankston

unread,
Aug 14, 2015, 8:36:39 PM8/14/15
to CefSharp
First I figured out how to wrap the created window using

            public bool OnBeforePopup(IWebBrowser browser, string sourceUrl, string targetUrl, ref int x, ref int y, ref int width, ref int height) {
                brf.InvokeOnUiThreadIfRequired(() => { var bf = new BRForm(targetUrl) { Visible = true }; });
                return true;
            }

But for the banking site I'm using this has a problem. If I don't create my own window and return false the PDF file gets displayed. If I do create my own it hangs -- I assume there is some parent/child type relationship taht is missing.

There's a separate issue with the PDF that I may list separately -- when the window is displaying the PDF how do I do the equivalent of hovering over SAVE to download the PDF.

Back to that window -- whether I create my own window or return false the following code failes

But first, the pop up problem+

    export function popped(ev: Event) {
        try {
            if (!window.name) window.name = "a";
            var me = window.location.href;
            var wo = <Window>window.open(me, window.name + "x");
            alert(`${window.name}: Got window ${wo}`);
            var fe = <HTMLElement>wo.document.body.firstElementChild;
            var h1 = wo.document.createElement("h2");
            fe.appendChild(h1);
            h1.innerText = window.name;
        }
        catch (e) {
            alert(`popped: ${e}`);
        }
    }

(The <>'s are TypeScript -- the disappear in the JavaScript)

The problem is that open seems to return a null or undefined value. But since the banking site window works if I return false I presume that there is a different parent/child relationship between the default browser window.


Alex Maitland

unread,
Aug 16, 2015, 8:35:34 AM8/16/15
to CefSharp
Is the PDF just a static file or is it generated somehow? If it's just opening a static file then it should be fine.

Without a sample it's a little hard to say what's going on. It might be worth trying to replicate the scenario by just opening a PDF in a similar fashion (might be worth creating a jsfiddle)

With the sample you provided there is no parent/child relationship between the browsers and as such you cannot access the opened window via javascript. There is an experimental feature in the `master` branch for providing your own ChromiumWebBrowser instance to handle a popup.

https://github.com/cefsharp/CefSharp/blob/master/CefSharp.Wpf.Example/Handlers/LifespanHandler.cs#L13

I'm not aware of a way to manipulate the PDF controls. It maybe possible in later versions of CEF. Background is http://www.magpcss.org/ceforum/viewtopic.php?f=6&t=13234 (it's not directly related, more about accessing the controls)

Alex Maitland

unread,
Aug 16, 2015, 8:43:37 AM8/16/15
to CefSharp
You basically have to download the file yourself. You can use the built in .net classes to download the file.

Alternatively in `master` you can use the `StartDownload` function which should retrieve the file from the cache.

https://github.com/cefsharp/CefSharp/blob/411497f08922449f54f5d035c44cdaf308a818a1/CefSharp/IBrowserHost.cs#L12

Bob Frankston

unread,
Aug 16, 2015, 10:07:29 AM8/16/15
to CefSharp

Thanks.

 

Some background. There's 20 years of history here. And lots of JIT (Just in Time) learning by doing. That results in a combination of deep understanding and naiveté.

 

I started going to the sites in raw html and then switched to MSHTML I use any technique that works including looking through temp directories for PDF files and moving the mouse programmatically (yeah, ugly). But about two years ago a security fix broke access to HTTPS sites. I switched to Awesomium and got most things working (and cleaned up a lot) except for some files (at mssb.com banking site) which I haven’t figured out. I tried using the URLs directly and looked for PDF files on disk but to no avail. No surprise that banking sites are challenges.

 

As to parent/child – my code examples are, of course, limited by the APIs. The new API does look richer – means more learning about using GITHUB beyond NUGET or waiting for the release of 43.


BTW, looking ahead I also need to figure out how to deal with secure iframes.

 

These issues are why I wrote http://rmf.vc/IEEEAPIFirst but I worry that HTML5 we’re making it increasingly difficult to have a peer relationship. I’m a great fan of HTML5 in general but not at the expense of an API. One of the “features” of HTML5 is to hide relationships to code limiting the utility of the dev tools.

 

Reply all
Reply to author
Forward
0 new messages