Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible to get/call webview event's manually through window code in node? #283

Open
conrad10781 opened this issue Mar 1, 2016 · 3 comments

Comments

@conrad10781
Copy link

I was investigating using Thrust as a replacement for a utility that we built in Qt using the QWebView. I'm not sure if I'm overlooking something, but is it possible to interact with the Javascript engine from the node.js javascript?

I'm trying to avoid rewriting large portions of this, so I'm battling issues now where all of the code/logic is in the C++, and we're basically just using the QWebView to render HTML.

To be more specific, it would be great if something like this could be done:

require("node-thrust")(function(err, api) { 
    window = api.window({ root_url: "/index.html" });
    window.show();
    ...
    window.on("load", function(err, ...){
        ...
        $(this).executeScript("alert('Hi');");
    });
});

I take it this is not possible to do with Thrust? I would need to modify all of our files to utilize the webview tags?

@miketheprogrammer
Copy link
Contributor

You can unsecurely do this using the thrust messaging API. Not sure if it
is implemented in the nodejs package. Essentially you can create your own
message format. That includes the JavaScript code, and then evaluate it on
the front end. Obviously you will not have access to closures.
On Mar 1, 2016 3:26 PM, "conrad10781" [email protected] wrote:

I was investigating using Thrust as a replacement for a utility that we
built in Qt using the QWebView. I'm not sure if I'm overlooking something,
but is it possible to interact with the Javascript engine from the node.js
javascript?

I'm trying to avoid rewriting large portions of this, so I'm battling
issues now where all of the code/logic is in the C++, and we're basically
just using the QWebView to render HTML.

To be more specific, it would be great if something like this could be
done:

require("node-thrust")(function(err, api) {
window = api.window({ root_url: "/index.html" });
window.show();
...
window.on("load", function(err, ...){
...
$(this).executeScript("alert('Hi');");
});
});

I take it this is not possible to do with Thrust? I would need to modify
all of our files to utilize the webview tags?


Reply to this email directly or view it on GitHub
#283.

@miketheprogrammer
Copy link
Contributor

i.e. Very very pseudo code, read the docs for real functions

in driver

Thrust.message( { id: 03193932, action: "Exec", msg: "alert('Hi')"

in html

thrust.on('message', function (d) { 
 // safe eval
  if (d.action === 'Exec' ) Function(d.msg) () 
})

@conrad10781
Copy link
Author

Thank you for the multiple follow-ups. Unfortunately, this would make it so that we would need to modify all the HTML files, which would be tenuous at best. What we're utilizing now is http://doc.qt.io/qt-4.8/qwebframe.html#evaluateJavaScript , which made it so we were able to build certain Javascript when needed and have the page execute it ( without the need to modify the HTML to accept ).

Thank you again for the follow-ups. We will definitely keep Thrust in mind for new projects we're building.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants