-
Notifications
You must be signed in to change notification settings - Fork 8
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
Copying links other than text doesn't appear to be working? #5
Comments
Same behavior for me with all links I've tried on AMO. The only place where it worked for me there was to copy the page link (when invoked from either the tab's context menu or the icon it places next to the address bar). So this seems to apply to AMO only, but works fine on all other sites I've tried so far. For the books: I've had the very same issues with Copy URL, so this could be a bug either in WebExtensions, or in the AMO page design (or in both, or AMO could willingly have done so). BUT: while on sites other than AMO the URL was captured fine, the link title was always set to that of the page the link was on – not to the link description (i.e. @Radagast can you confirm this? Looks like this could become a replacement for CoLT when legacy addons are shot down with FF57 – provided the (PS: AMO = Addons.Mozilla.Org) |
@IzzySoft Thanks for your comment. Your observations are the same as mine. I described them at "KNOWN LIMITATIONS" in https://addons.mozilla.org/ja/firefox/addon/format-link3/ I believe these are limitations of the web extension APIs. For context menus, I use FormatLink-Firefox/background.js Line 34 in d494ccf
But the |
Thanks for your feedback, @hnakamur – I vaguely remembered having read about some such limitation but didn't remember where (Mozilla drives me crazy with their breaking everything every few years; I'm using Firefox since back when it was called Phoenix, and only didn't switch because I haven't yet found a suitable alternative – so this is about the 3rd time I've got to completely "restock" my extensions). With the WebExt API still not being "finished" by them, is there any chance this limitation might be removed in the future? I'm not a FF or Chrome dev and not familiar with it, but I would expect even an API as limited as that one should be able to retrieve the link's nodeValue as well – so my hope is this is something they'll add?
Strike the last paragraph. No nodeValue/title/whatever available at the moment, I've just checked. And it seems unlikely to be added, as even the original Chrome API Mozilla is "cloning" doesn't have it. Sad. The only way to get those details really is |
PS: @hnakamur you might wish to check into this bugzilla issue. Is exactly about the "link title", and still open. As for the "alternative approach" I mentioned in my previous comment, it has even that: function menuClick(info, tab) {
let url = new URL(info.linkUrl);
browser.tabs.executeScript(tab.id, {
code: `
var link = document.querySelector('a[href="${url.pathname}"]');
....
`
}); (if the same link exists multiple times, as a work-around you could just pick the first one. Shouldn't happen too frequently anyway, hopefully). Chime in there, point out that your addon (and the other one I've mentioned I used to verify) would need that in |
Thanks! Just tested it (loading it as "temporary extension" via about:debugging). Strange. Works for some links, but not for others. Reproducible:
Same "mixed bag" on other sites. Tried at Stack Exchange: Links from the content work fine, from the headers not. Here at least is some clue: those which do not work have some event handler attached. Oh, guess what: for "click", so that could interfere (however, CoLT captures them correctly). Didn't see any event attached to those "failed links" on the Github page, though. Some debug via Console (back again on your Github page) indeed matches that: document.querySelector('a[href="https://github.com/hnakamur/FormatLink-Firefox/branches"]')
// returns: null
document.querySelector('a[href="https://github.com/hnakamur/FormatLink-Firefox/blob/master/LICENSE"]')
// <a href="https://github.com/hnakamur/FormatLink-Firefox/blob/master/LICENSE"> So for the failing links, Suggested fix: In if (link) then link.innerText.trim() : "";
else {
link = document.querySelector('a[href="${url}.pathname"]');
link ? link.innerText.trim() : "";
} (well, syntax error for the new URL – but you get what I mean). Basically: If the full URL was not found on the page, try again with the path only. But of course only if the hostname in the URL matches the hostname of the page. I'm ready to test that again, just let me know when it's ready :) |
Fantastico! I was one step behind you (have tried in parallel, got the relative URLs working and was just about to deal with anchors as well – your fix already includes that. Strange that looping over all links ( So: Works like a charm now – except for AMO pages, strangely, where it still doesn't catch a thing. Rushes right through tryToGetLinkSelectionText as if it would "return Promise…", though "text" is undefined. Tried selecting some text – and ran into an exception with that, claiming on line 78 that For now I'd suggest to publish the next version and leave the AMO issue for later (as that has its separate issue, guess this one can be considered solved and be closed now). Thanks a lot for your help! If I do the switch to FF57, this will now be my replacement for CoLT. 👍 |
Thanks for your test and comment. I suppose Code for context menu and copying text to clipboard are copied from
To copy text to clipboard, you need to inject JavaScript to web pages, but you cannot do that in the addons.mozilla.org for security reason. As for copyTextToClipboard, yes I see the error I copied the code from I submitted the version 1.3.3 for the review. Thanks a lot for your help, too! |
Typical win-win situation then 😁 As for AMO: the (legacy) addon CoLT can extract URLs fine from there. Guess one could play with parsing the DOM tree to see whether that's possible (and also working with AMO and other possibly "restricted sites"). For now I guess your addon will work on 95% of all sites or more, and that's a good thing! I've updated my Gist accordingly, naming your addon as only possible replacement for CoLT (as the other candidates fail on too many things). Yours has even an advantage over CoLT: I can chose to let the copied link have a different title by simply selecting some text from the page 🤣 One minor (cosmetic) suggestion (
Alternatively: "using %s format" (e.g. "using default format", "using Markdown format"). Nothing urgent, just cosmetical 😉 Finally, my big thanks for your great support! Need to remember to mention that in my Gist. |
Thanks for your advice! |
Thanks! Update arrived and looks great! Funnily I still found a few "misbehaving links" (unfortunately in a protected area you'll have no access to). If I figure what it is (and maybe cann present an openly accessible example) I'll let you know. |
Okay, checklist of my findings. Pages that do not work include:
Just removed some bullet points from above list. If someone reports "wrong titles" or "not working at all", there are a few cases where that is "expected behavior":
Will keep my eyes open. Apart from above "minor annoyances", it works pretty well now! |
It generally works fine for me on Windows. But on Linux, I find that it only works if I've never copied anything to the clipboard since logging in. Once I've copied something to the clipboard in another program, then Format Link stops working (clipboard still contains the previous thing copied). I am guessing this is a limitation of the Firefox WebExtensions implementation on Linux. |
Thanks for fixing the missing context menu options on Nightly. Unfortunately, copying links in anything other than plain text doesn't appear to be working. For example, if I select the FormatLink-Firefox at the top of this page and select copy as markdown, nothing gets added to the clipboard and hence there's nothing to paste.
Linux/Nightly.
The text was updated successfully, but these errors were encountered: