Home > Net >  Create simple Chrome extension - single click forward tab url to https
Create simple Chrome extension - single click forward tab url to https

Time:08-07

trying to create a extremely simple chrome extension, but need some help.

Purpose: When I click the extension icon, URL of existing tab must be forwarded to telegram. This can be done via a HTTPS call like https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text=https://activetab.url

Single extension button, when clicked:

  • Grab URL of active link
  • Post http enriched with link url grabbed in previous step

No security concerns, I want to install the extension in developer mode only in my own browser. Goldplated option would be to let the user specify the bot, the token & recipient id in settings of the app.

Thx for any feedback

CodePudding user response:

It should only take a few lines of code.
I assumed that the http request is of type: "GET".
If not, you have to modify the fetch command according to Telegram specifications.

//manifest.json
{
    ...
    "background": {
        "service_worker": "background.js"
    },
    "action": {
        "default_icon": {               // optional
            "16": "images/icon16.png",  // optional
            ...
        },
        "default_title": "Click Me"     // optional
    },
    
    "permissions": ["tabs"]
    ...
}


//background.js
chrome.action.onClick.addListener(t => fetch('https://api.telegram.org/bot123456:xxxxxxxxxxxxxxxxxxxxxx/sendMessage?chat_id=12345678&text='   tab.url))
  • Related