Need help with handling popups

Having problems with building or using the JCEF Java binding? Ask your questions here.

Need help with handling popups

Postby JohnnyTheHun » Sun Feb 17, 2019 4:45 am

Hello,

Our webpage sometimes sends a file to download via the javascript window.open(...), e.g.:
window.open('https://oursite.com/Downloads/something.xls');

I have a downloadhandler added to the cefclient and if I use the php command header("Location: 'https://oursite.com/Downloads/something.xls'''); instead of a javascript window.open(...) the download works perfectly.

The window.open method works on a desktop chrome browser. But if I use the window.open method from our integrated java-cef browser it currently only opens a blank popup window.
To check what's happening I added a LifSpanHandler:
Code: Select all
 
client_.addLifeSpanHandler(new CefLifeSpanHandlerAdapter() {
            @Override
            public boolean onBeforePopup(CefBrowser br, CefFrame cf, String url, String target_frame_name) {               
                System.out.println("On Before popup: url="+url+", target_frame_name="+target_frame_name);
                System.out.println("Client: "+br.getClient()); //this shows the same String as client_.toString();
                return false;
            }
        });

And it shows that url is https://oursite.com/Downloads/something.xls as it should be, so it is trying to open a popup for the file.

I want the download handler to work in the window.open(...) situation too, what would you recommend?

Thank you!
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby Phylanx » Mon Feb 18, 2019 2:01 am

My quick guess would be that for the new window a new CefBrowser is created.
You would have to add a DownloadHandler there too.
Phylanx
Expert
 
Posts: 147
Joined: Thu Aug 11, 2016 8:17 am

Re: Need help with handling popups

Postby JohnnyTheHun » Mon Feb 18, 2019 3:39 pm

If I understand correctly you would recommend me to handle the popup in the onBeforePopup function and return true so it doesn't get handled again?

That might work, but I still don't understand why it doesn't in its current state. You cannot set a downloadhandler for a CefBrowser, you can set it at the CefClient. But it seems the CefBrowser argument in the onBeforePopup is linked to the same CefClient (at least that is what I deducted since the origivel _client.toString() and the br.getClient().toString() returns the same value).

So since the downloadhandler is set at the CefClient and works in other circumstances why doesn't it work here? Should I really create a new CefClient and a New CefBrowser for the popup to download a file if a file has been requested via window.open(...)?

Janos
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby JohnnyTheHun » Sat Aug 10, 2019 2:22 pm

Has anybody found an optimal solution for this?
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby JohnnyTheHun » Thu Jul 02, 2020 5:23 am

I have successfully solved this with creating a custom popup in the onBeforePopup function.
But a strange thing is happening now:
whenever a window.open(...) opens a png (or any picture or any pdf) file, the popup works.
BUT if I upload a file beforehand, and then do a window.open(...) that opens the same png that worked before, it doesn't work anymore, it only shows a blank window.

What I found is that before uploading the file the following methods get called:
Code: Select all
On Before popup: url=.....pdf, target_frame_name=jav
onLoadingStateChange in browser 2: |isLoading:true|canGoBack:false|canGoForward:false|
onBeforeBrowse: .....pdf
java.lang.NoSuchMethodError: onBeforePluginLoad
onLoadStart: |[....pdf]|TT_EXPLICIT|
java.lang.NoSuchMethodError: onBeforePluginLoad
onAddressChange: |[[...].pdf]|[...].pdf|
onLoadEnd: |[....pdf]|200|
onLoadingStateChange in browser 2: |isLoading:false|canGoBack:false|canGoForward:false|



And after I've uploaded the file, the methods that get called are different:
Code: Select all
On Before popup: url=.....pdf, target_frame_name=jav
onLoadingStateChange in browser 5: |isLoading:true|canGoBack:false|canGoForward:false|
onBeforeBrowse: .......pdf
onLoadingStateChange in browser 5: |isLoading:false|canGoBack:false|canGoForward:false|


There is no onLoadStart, no onAddressChange and no onLoadEnd....

The same applies if I try to open a png file (so not only pdf-s do this).

Has anyone run into this before? I am using jcef_version 3.3538.199.gd64cd6c
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm

Re: Need help with handling popups

Postby JohnnyTheHun » Thu Sep 24, 2020 3:30 am

For the record: the version of jcef I was using had issues handling file upload forms if the file input tag had the multiple option.
JohnnyTheHun
Techie
 
Posts: 42
Joined: Tue Apr 10, 2018 12:24 pm


Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 1 guest