Cefframe Copy / Paste not working

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

Cefframe Copy / Paste not working

Postby JCEFBeginner » Fri Jun 11, 2021 10:42 am

Hello,

I have a problem with copying something programmatically.

I have the following code in my application:

Code: Select all
client.addKeyboardHandler(new CefKeyboardHandlerAdapter() {
            @Override
            public boolean onKeyEvent(CefBrowser browser, CefKeyEvent event) {
                if (event.type == CefKeyEvent.EventType.KEYEVENT_CHAR && event.modifiers == KeyEvent.BUTTON3_MASK) {
                    if (Character.toLowerCase(event.native_key_code) == 'c') {
                        browser.getFocusedFrame().copy();
                    }
                    if (Character.toLowerCase(event.native_key_code) == 'v') {
                        browser.getFocusedFrame().paste();
                    }
                    if (Character.toLowerCase(event.native_key_code) == 'x') {
                        browser.getFocusedFrame().cut();
                    }
                }
                return true;
            }
        });


I tested the code with a debugger. After the copy call, the clipboard is cleared.
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: Cefframe Copy / Paste not working

Postby JCEFBeginner » Fri Jul 16, 2021 9:38 am

Hello?
Is no one reading this thread, or does no one have an idea?
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: Cefframe Copy / Paste not working

Postby Czarek » Sat Jul 17, 2021 10:16 am

What if you execute javascript code to interact with clipboard? See https://developer.mozilla.org/en-US/doc ... _clipboard
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cefframe Copy / Paste not working

Postby Phylanx » Mon Jul 19, 2021 1:41 am

Hi!

We had the problem that in some PDFs the context menu copy action didn't work.
We fixed it with our own ContextMenuHandler and using Java AWTs Toolkit.

Hope it helps...

Code: Select all
    class CopyContextMenuHandler
            implements CefContextMenuHandler
    {
        @Override
        public void onBeforeContextMenu(CefBrowser P_browser,
                                        CefFrame P_frame,
                                        CefContextMenuParams P_params,
                                        CefMenuModel P_model)
        {
            logger.debug("CopyContextMenuHandler.onBeforeContextMenu called!");
        }

        @Override
        public boolean onContextMenuCommand(CefBrowser P_browser,
                                            CefFrame P_frame,
                                            CefContextMenuParams P_params,
                                            int Pi_commandId,
                                            int Pi_eventFlags)
        {
            logger.debug("CopyContextMenuHandler.onContextMenuCommand called!");
            if (Pi_commandId == CefMenuModel.MenuId.MENU_ID_COPY)
            {
                logger.info("CopyContextMenuHandler copy command was overwritten!");
                Clipboard F_clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
                StringSelection F_stringContent = new StringSelection(P_params.getSelectionText());
                F_clipboard.setContents(F_stringContent, F_stringContent);
                logger.debug("Handling copying text with our copy fix!");
                return true;
            }
            return false;
        }

        @Override
        public void onContextMenuDismissed(CefBrowser P_browser, CefFrame P_frame)
        {
            logger.debug("CopyContextMenuHandler.onContextMenuDismissed called!");
        }
    }
Phylanx
Expert
 
Posts: 201
Joined: Thu Aug 11, 2016 8:17 am

Re: Cefframe Copy / Paste not working

Postby JCEFBeginner » Tue Jul 20, 2021 11:12 am

Hello,

Thank you for your answers @Phylanx developers and @Czarek! ;)

@Phylanx, I currently disabled the Context Menu of JCEF, because of problems with it. (If I trigger the Context Menu, I can't click with the mouse anymore.)

@Czarek, It is not working I tested it with https://permission.site/ and all copy commands failed.
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: Cefframe Copy / Paste not working

Postby Czarek » Tue Jul 20, 2021 12:20 pm

Does it occur on specific websites or all of them? Does it reproduce with jcef original examples?
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cefframe Copy / Paste not working

Postby JCEFBeginner » Tue Jul 20, 2021 1:43 pm

I found out that the problem only persists, if off-screen-rendering is enabled.
I think the pages are not the cause of the problem. Furthermore, I tested it out on permission.site, Google and a local HTML File.
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: Cefframe Copy / Paste not working

Postby Czarek » Tue Jul 20, 2021 4:33 pm

I've found an issue in the tracker that says enabling multi threaded message loop resolved clipboard issue, you could try that. You could also test with C++ CEF sample app to see if it reproduces.
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Re: Cefframe Copy / Paste not working

Postby JCEFBeginner » Thu Jul 22, 2021 10:14 am

Sorry, but I don't know how to enable multithreaded message loop. :?:
JCEFBeginner
Techie
 
Posts: 18
Joined: Fri Feb 12, 2021 12:17 pm

Re: Cefframe Copy / Paste not working

Postby Czarek » Thu Jul 22, 2021 12:15 pm

Looks like it is enabled by default in java-cef: https://github.com/chromiumembedded/jav ... t.cpp#L206
Maintainer of the CEF Python, PHP Desktop and CEF C API projects. My LinkedIn.
User avatar
Czarek
Virtuoso
 
Posts: 1927
Joined: Sun Nov 06, 2011 2:12 am

Next

Return to JCEF Forum

Who is online

Users browsing this forum: No registered users and 7 guests