Amit
Amit

Reputation: 11

Trigger custom DOM event and consume DOM event received in Java Eclipse RCP-- JXBrowser

I need to trigger the following custom DOM event

const event = new CustomEvent('GTWEvent', { detail: { command: 'REQACCT' } }); window.dispatchEvent(event);

Once I dispatch the above DOM event, I will receive a "CDMEvent" in response, which will contain attributes such as account, type, etc. I need to consume this DOM event and process the data.

Note: Need to write code in java, i am working on eclipse RCP(JXBrowser)

I have tried many ways using

jxbrowser.getBrowser().mainFrame().get().executeJavaScript("const event = new CustomEvent('GTWEvent', { detail: { command: 'REQACCT' } }); window.dispatchEvent(event);")

Upvotes: 1

Views: 33

Answers (1)

Vladimir
Vladimir

Reputation: 2277

Try using JxBrowser DOM API as shown in the code below:

browser.mainFrame().ifPresent(frame -> {
    frame.document().ifPresent(document -> {
        CustomEventParams eventParams =
                CustomEventParams.newBuilder(document)
                        .detail("command: REQACCT")
                        .build();
        CustomEvent event = document.createCustomEvent(
                EventType.of("GTWEvent"), eventParams);
        document.dispatch(event);
    });
});

Upvotes: 0

Related Questions