Open noahgibbs opened 8 months ago
Here's some other folks dealing with a similar GitHub-specific issue. https://github.com/microsoft/Mezzurite-DevTools/issues/27
I suspect the answer is that for a link to navigate to a web page, we should be catching the event and calling navigate(). I assume that would fix the problem, though I haven't tested it.
Hey @noahgibbs , I wanna work on this issue. Could you please assign this to me?
Cool! Assigned. The interesting part of this one is going to be figuring out how to do it all in the display service -- you shouldn't need to mess with Lacci for this, since it's basically a Webview detail. Let me know if you'd like help looking through stuff.
Cool! Assigned. The interesting part of this one is going to be figuring out how to do it all in the display service -- you shouldn't need to mess with Lacci for this, since it's basically a Webview detail. Let me know if you'd like help looking through stuff.
Thank you for the help and guidance in advance. I'm looking into the display service's role in handling Webview details for this matter. Could you provide some guidance on how the display service interacts with the Webview and if there are specific methods or components I should focus on? How to approach the issue in correct way?
Pretty much all Webview stuff is wrapped up in the WebWrangler. So that's your starting point. You can see an existing call to navigate() there -- but just one, that happens when the app starts. You'll probably need to add another one, or change how it does it.
One way to do this (I think) would be to stop using normal HTML links that use the href, and instead have links with an onclick() that call through to Ruby and calls navigate(). I assume that would fix the problem, though I haven't tested it. That should let it all be in Webview where it belongs without messing with Lacci. You'll probably want to add a new Ruby method with bind() and then add it as an onclick handler for links.
These are generated links (e.g. examples/link.rb), so you'll want to change what HTML is generated for them. Links have a Webview-side drawable (lib/scarpe/wv/link.rb) that just passes them to Calzini as a text drawable with "a" as the tag. If you make sure has_block is set when you pass it to Calzini, you'll always get an onclick handler that tells the Webview drawable when it's clicked on. So that's one way you could handle it.
Calzini does the rendering in scarpe-components/lib/scarpe/components/calzini/para.rb. So another way you could handle it is by changing how it sets up the onclick handler (see text_drawable_attrs).
But one way or another, you need to make sure that even if no block is set, there's an onclick handler, and that you call the navigate() method to move to the new page in response to that onclick handler.
Navigating directly there should fix the problem. Here's an example program to show that:
require "webview_ruby"
# GitHub has problems due to CORS if you click on an a link leading to it.
# But navigating directly there is fine, with no CORS errors on console.
webview = WebviewRuby::Webview.new debug: true
webview.set_title("Example")
webview.set_size(480, 360)
webview.navigate("https://github.com/scarpe-team/scarpe")
webview.run
# Make sure no console errors
webview.destroy
Hey @noahgibbs , I tried implementing the suggested approach using the navigate method, but it is not working out, it is throwing error - "undefined method naviagte", or maybe I am implementing it wrong somehow. I will go through it again, to see if there is a mistake in implementation.
Though, I am able to open that GitHub link in examples/link.rb by an alternate approach, by using system command xdg-open
, though this might only work for Linux-based distributions but I was thinking maybe we could implement switch-cases for all operating systems(Mac-OS, Linux and Windows) ?
"undefined method naviagte"
That looks like maybe you're spelling "navigate" wrong, based on what you write here. The system command is going to do something very different, and not really what we want.
"undefined method naviagte"
That looks like maybe you're spelling "navigate" wrong, based on what you write here. The system command is going to do something very different, and not really what we want.
Well, that was an honest spelling mistake here. I checked VSC, spellings are correct. I think I didn't understood code right.
You'll probably need to add another one, or change how it does it.
I need to add that example program's logic that you provided in previous reply in example/link.rb, right ?
So, the example program is showing you how to use the navigate method on the Webview API object, the same one that's called @view in WebWrangler to do initial setup. But if you're getting an undefined method, that means you're not successfully calling navigate on the Webview object. That doesn't sound like a "Webview doesn't work" problem (though those exist.) That sounds like a problem with making sure you're calling the right method on the right object.
If you have the code somewhere I can look at it, I can probably tell you why navigate isn't getting called on the right object.
Just adding the example program's code in link.rb won't work. You need to call .navigate on the Webview object that's being used underneath Scarpe -- the one that already exists. If you try to make a new Webview object, usually you'll get a crash.
So: this probably needs a new WebWrangler API to call Webview's navigate. That API needs to be called when you click on a link. Not just the link in examples/link.rb, but any link. You can add an onclick handler in JS to call a bound-to-Ruby method -- that's one place, and probably the easiest, to call that WebWrangler API. To make the bound-to-Ruby method, you'll need to call @view.bind in the WebWrangler. You can find examples of bound-to-Ruby methods in the WebWrangler by looking for ".bind" -- for instance scarpeHeartbeat is one. Then when JS calls scarpeHeartbeat, it calls the Ruby method asynchronously (you can see a setInterval call that does this for scarpeHeartbeat in particular.)
You're doing the same general kind of thing. You might call your bound method something like "scarpeNavigate". Then your links will need an onclick handler, something like onclick="scarpeNavigate('whateverURL')"
. Does that make sense? Alternately, would you like to pair on this?
I would really love to pair but I'll be able to work directly on Tuesday as right now I am travelling. I'll comment here when I'll be available.
Sounds good. Let me know when :-)
Sounds good. Let me know when :-)
Hey @noahgibbs , I am available to start working on this issue. Let me know when and how we could connect to start working on it.
Hey @noahgibbs , I was able to overcome the error(that was coming after click) message but link is still not opening. I was thinking maybe I could open a draft PR for what I have done till now and then maybe we could work on that or you could review it and suggest changes that needs to be done?
Sure, that sounds good. Sorry for not getting back to you sooner. I'm also potentially available tomorrow or this weekend if you'd like to do a Zoom call or similar.
Sure, that sounds good. Sorry for not getting back to you sooner. I'm also potentially available tomorrow or this weekend if you'd like to do a Zoom call or similar.
No problem. Weekend sounds great. I have some personal commitments for tomorrow.
For instance, run examples/link.rb. It fails with a message about GitHub's content security policy:
It seems to be a problem with clicking a normal "a" link, but maybe it's because we're doing that instead of navigate? We should at least try prototyping having link() call navigate from Ruby instead of a regular a link.