最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin2浏览0评论

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);")

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);")

Share Improve this question asked Feb 6 at 11:34 AmitAmit 111 bronze badge New contributor Amit is a new contributor to this site. Take care in asking for clarification, commenting, and answering. Check out our Code of Conduct.
Add a comment  | 

1 Answer 1

Reset to default 0

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);
    });
});
发布评论

评论列表(0)

  1. 暂无评论