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

Please add example for "Paste text from clipboard" #521

Closed
Hellboy00000 opened this issue Mar 25, 2023 · 5 comments
Closed

Please add example for "Paste text from clipboard" #521

Hellboy00000 opened this issue Mar 25, 2023 · 5 comments
Labels
needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened.

Comments

@Hellboy00000
Copy link

Hellboy00000 commented Mar 25, 2023

This is in a background.js

This code can be used to create the example:

browser.menus.create({
id: "whatever",
title: "Paste clipboard Text"
});

browser.menus.onClicked.addListener((info, tab) => {
navigator.clipboard.writeText("Paste Hello"); // This add the code to the clipboard
// The code needed to paste the text
});

The context menu is not needed for the "paste code" i want to see, but i think that with this example is more easy for everyone to understand the code.

Thanks

@Hellboy00000 Hellboy00000 added the needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened. label Mar 25, 2023
@rebloor
Copy link
Collaborator

rebloor commented Mar 27, 2023

@Hellboy00000
Copy link
Author

I try that but that example is using HTML (where it looks for a ID of the text area) and i don't use any HTML. I just want to "paste" in a web page in a browser using the extension.

When i use that code say execCommand is deprecated.

@Rob--W
Copy link
Member

Rob--W commented Apr 3, 2023

The question you're asking and the code snippet are two different things.

"Paste" means reading from the clipboard.
The writeText call in the snippet writes to the clipboard, that's called "Copy".

What do you want that is not already covered in https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard ?

@Hellboy00000
Copy link
Author

Hellboy00000 commented Apr 6, 2023

I try that but that example use HTML to look for the ID of the text area were the text is going to be pasted. I really don't know how to do it. So if someone can share a example preferably with code i first share i am going to be really grateful.

Edit: Or this code to try to put the text in the comment or the search bar using this page.

browser.menus.create({
id: "whatever",
title: "Paste clipboard Text"
});

browser.menus.onClicked.addListener((info, tab) => {
let url = browser.tabs.query({ active: true, currentWindow: true }).then(function (tabs) { url = tabs[0].url; });
if (url === "#521") {
navigator.clipboard.writeText("Paste Hello"); // This add the code to the clipboard
// The code needed to paste the text
}
});

@rebloor
Copy link
Collaborator

rebloor commented Apr 9, 2023

@Rob--W I think that @Hellboy00000 is looking for code to allow his extension to paste into a webpage. My understanding is you can't do that in code, the user has to initiate the paste. All the code can do is add or remove content from the clipboard.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Triage needed by staff and/or partners. Automatically applied when an issue is opened.
Projects
None yet
Development

No branches or pull requests

3 participants