Skip to content

Is it possible to call SingleFile from an extension? #1225

@silarri

Description

@silarri

I'm trying to call the SingleFile extension from a custom button that performs several actions that are typical in my workflow. My code in the background.js file is as follows:

  const targetExtensionID = "{531906d3-e22f-4a6c-a102-8057b88a1a63}";
  await browser.runtime.sendMessage(targetExtensionID, { action: "ACTION_SAVE_PAGE" })
    .then(response => {
      // Handle the response from the other extension if needed
      recordLog("Received response from SingleFile extension: " + response);
    })
    .catch(error => {
      // Handle any errors that may occur
      recordError("Error sending message to SingleFile extension: " + error);
    });

When I execute that code, I get the message "Received response from SingleFile extension: undefined", but nothing seems to happen. Any idea of what could be failing here?

It seems that the message is correctly sent to the SingleFile extension, as if I change the targetExtensionID then I get an error "Error sending message: Error: Could not establish connection. Receiving end does not exist.". This also begs another question: the target extension ID seems to be quite arbitrary (it is not even set in the manifest.json file of SingleFile, as far as I understand), so the code above seems to be quite fragile (it depends on an ID that has no meaning for me and could change). Any idea about whether this can be managed in a better way is welcome.

Any tip would be great!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions