save-in icon indicating copy to clipboard operation
save-in copied to clipboard

Feature Request: allow other extensions to pass a URL to Save In

Open KernelLeak opened this issue 6 years ago • 11 comments
trafficstars

I was trying to hook up Save In in Foxy Gestures by using browser.sendMessage with the optional extensionId parameter, only to find out that this works only when a listener for browser.runtime.onMessageExternal has been installed and not with the regular browser.runtime.onMessage handler... :(

Could you please add a handler for onMessageExternal so you can for example use Foxy Gestures' user script feature to pass the URL of an image to Save In via a DOWNLOAD message?

KernelLeak avatar May 04 '19 22:05 KernelLeak

This is something I'm interested in doing. I'll try to get it done when I have some spare time.

gyng avatar May 05 '19 16:05 gyng

I too am interested and am glad to help and to test attempts. I use uget with its official setup and follow your repo so here if you need me.

DanaMW avatar May 05 '19 17:05 DanaMW

I've done a quick update to allow for this in 3.5.0, but I'm not a user of Foxy Gestures.

Take a look at https://github.com/gyng/save-in/wiki/Use-with-Foxy-Gestures and see if it works.

gyng avatar May 20 '19 08:05 gyng

Thank you for adding this hook. I'm testing it out in Gesturefy, which appears to have similar "send message to other addon" integration:

image

I'm no good at scripting, though. How would I need to modify your supplied sample code to just make this send a command to open the Save In menu? (assuming that's possible, which I suppose we'll find out together.)

tombones avatar May 21 '19 14:05 tombones

Just noticed this upgrade and will test right now thanks for your work once again friend.

DanaMW avatar May 21 '19 16:05 DanaMW

Well, it does almost work. I'm sending the following payload via browser.runtime.sendMessage:

{
  "type": "DOWNLOAD",
  "body": {
    "url": "http://wapsisquare.com/wp-content/uploads/2019/05/nudge.jpg",
    "info": {
      "pageUrl": "http://wapsisquare.com/",
      "srcUrl": "http://wapsisquare.com/wp-content/uploads/2019/05/nudge.jpg",
      "comment": null
    }
  }
}

But then I get a toast stating "Save In: Failed to route or rename download" and it pops the standard Save As dialog, as expected when it can't route.

If I use the context menu's "Save In route..." it works as expected, so I'm pretty sure I've set up my routes correctly. Maybe the parameters I passed got mixed up along the line?

The code I used in Foxy Gestures was the following:

var source = data.element.mediaSource;

if (source) {
    const payload = {
        type: "DOWNLOAD",
        body: {
            url: source,
            info: { pageUrl: `${window.location}`, srcUrl: source, comment: null }
        }
    };

    browser.runtime.sendMessage("{72d92df5-2aa0-4b06-b807-aa21767545cd}", payload);
}

KernelLeak avatar May 21 '19 16:05 KernelLeak

Well, debugging the extension it seems that in download.js in line 57 in getRoutingMatches you expect the passed info object to have a legacyDownloadInfo member and pass that as the info object to Router.matchRules, but here it's actually undefined...

But since the parameter in matchRules is called info shouldn't the info object itself have been passed here, or at least if legacyDownloadInfo is null?

KernelLeak avatar May 21 '19 16:05 KernelLeak

@KernelLeak thanks for taking the time to debug. I think it's got to do with a rule, since it works on a fresh install. If you are able to find out which rule is causing the problem and paste a version of it here it'll help me debug it.

2019-05-22_02-44-30

It's really confusing in the router.js because info is actually legacyDownloadInfo. I removed it once before last year but reverted it. Anyway, I've put a quick untested release with legacyDownloadInfo ripped out at https://github.com/gyng/save-in/releases/tag/v3.5.1-a1, if you care to try untested code. (Or if you're adventurous enough I'm open to PRs...)

@tombones I tried poking around Gesturefy, but I don't see any way to run arbitrary JS or send dynamic messages to another addon. I'm only able to send static JSON strings, nothing else. Maybe you can ask around on Gesturefy's support after this feature gets more ironed out.

gyng avatar May 21 '19 18:05 gyng

Well, since I'm not an add-on developer and haven't set my Firefox up for developing extensions I just took the 3.5.0 XPI, shoved the three changed JS files into it, disabled XPI signature checking in my Firefox Developer Edition and did a "Install extension from file..." - and now it works.

I'm pretty sure there must have been a deviation in both codepaths that made the original (mouseclick) one work but not the new (sendMessage) one, but I hope you don't mind me not trying to find out what it was exactly... :)

(I'm too busy watching our (Austrian) government fall apart right now to do more develop-y things...)

KernelLeak avatar May 21 '19 19:05 KernelLeak

@KernelLeak thanks for the update. By "three files" did you mean the edited files from 3.5.1-a1?

gyng avatar May 22 '19 11:05 gyng

Yes, I meant the three files in the src folder that changed from 3.5.0 to 3.5.1-a1.

KernelLeak avatar May 22 '19 12:05 KernelLeak