Getting url from active tab on external page - firefox-addon

I have create a very simple addon for personal use. The only thing it does is show a "popup" with an external url. So far it works fine, but now I of course want to add features. For this I would like to access the url of the tab on which the extension is opened. I have tried many things, but I can't seem to put my finger on it. I would also be glad with the url being added as a parameter to the url of "default_popup".
This is my manifest.json:
{
"browser_action": {
"browser_style": true,
"default_title": "Name of addon",
"default_popup": "https://www.testdomain.com/dir/"
},
"icons": {
"48": "lock.svg",
"96": "lock.svg"
},
"description": "Open given page in window on top of browser I guess...?",
"manifest_version": 2,
"name": "Name of addon",
"version": "1.0.11",
"permissions": [
"tabs"
],
"applications": {
"gecko": {
"id": "name#testdomain.com"
}
}
}
It's probably just a simple thing for you seasoned developers, but I have only started today :)

You'll have to declare the popup to use a page that belongs to the extension. The script inside that page will be able to get the current tab's URL and redirect the popup to the external site.
manifest.json, inside browser_action section:
"default_popup": "popup.html"
Create popup.html:
<script src="popup.js"></script>
Create popup.js:
(async () => {
const [tab] = await browser.tabs.query({active: true, currentWindow: true});
location.href = 'https://www.example.com/?foo=' + encodeURIComponent(tab.url);
})();

Related

Is there a way to start conversation when teams tab is created using graph api

I am creating a teams app where there is an option to create a new tab for collaboration for individual/group by providing details like tab display title, url etc
After the tab is created, I would want to send some supporting message to describe about the tab.
Right now there is button to start conversation. And when you click on button some prefilled text loads along with tab title.
Is there a way I can achieve this using graph api, so instead of clicking on start conversation button and getting the pre-filled message, I should be able to pass the supporting message via the graph api ?
Or Can we customize the message shown once you click the start conversation?
once you create a Tab in Team's channel via graph api you should get 201 as success with ID of new tab.
HTTP/1.1 201 Created
Content-type: application/json
{
"id": "794f0e4e-4d10-4bb5-9079-3a465a629eff",
"displayName": "My Contoso Tab",
"configuration": {
"entityId": "2DCA2E6C7A10415CAF6B8AB6661B3154",
"contentUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/tabView",
"websiteUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154",
"removeUrl": "https://www.contoso.com/Orders/2DCA2E6C7A10415CAF6B8AB6661B3154/uninstallTab"
},
"sortOrderIndex": "20",
"webUrl": "https://teams.microsoft.com/l/channel/19%3ac2e36757ee744c569e70b385e6dd79b6%40thread.skype/tab%3a%3afd736d46-51ed-4c0b-9b23-e67ca354bb24?label=my%20%contoso%to%tab"
}
Then you can create conversation like below
POST https://graph.microsoft.com/v1.0/groups/29981b6a-0e57-42dc-94c9-cd24f5306196/conversations
Content-type: application/json
{
"topic": "Take your wellness days and rest",
"threads": [
{
"posts": [
{
"body": {
"contentType": "html",
"content": "Contoso cares about you: Rest and Recharge"
},
"newParticipants": [
{
"emailAddress": {
"name": "Adele Vance",
"address": "AdeleV#contoso.onmicrosoft.com"
}
}
]
}
]
}
]
}
Ref articles

Swagger: How to make "Execute" button disabled if required parameters haven't been informed

I am using Swagger UI Express to create docs to a very simple node API. It's more a "UI/UX" question, but is bothering me.
I have routes where a path parameter is required (client id, for instance), and I have documented this way. So, the parameter on Swagger UI is marked as required. However, user is able to click on "Execute" button without filling in the required parameter. This would not be a big problem if the page returned an error and let the user fill the required parameter and try again, but is not what it is happening. After clicking the button, a loading gif appears and keeps loading... Even if the user click on "Cancel" button, it is not stopping from loading.
On console, the follow error appears:
react_devtools_backend.js:4026 Error: Required parameter codCliente is not provided
at index.js:233:13
at Array.forEach (<anonymous>)
at Object.Bn [as buildRequest] (index.js:200:22)
at actions.js:452:24
at Object.dispatch (utils.js:177:16)
at dispatch (<anonymous>:3665:80)
at redux.js:546:12
at wrap-actions.js:33:10
at Object.r (system.js:175:26)
at Object.executeRequest (system.js:487:14)
Here is a screenshot of problem happening. We can see the parameter as required but the UI let you click on "Try it out" and then click on "Execute".
Here is an example of router and controller code:
const getByCod = async (req: Request, res: Response): Promise<Response> => {
const { codCliente } = req.params;
const cliente = await clientesService.getByCod(parseInt(codCliente, 10));
return res.status(StatusCodes.OK).json({ data: cliente });
};
clientesRouter.get(
'clientes/:codCliente',
authenticationMiddleware,
authorizationMiddleware,
getByCod,
);
And here my swagger path definition inside swagger.json:
"/clientes/{codCliente}": {
"get": {
"summary": '...',
"description": '...',
"tags": ["Clientes"],
"security": [...],
"parameters": [
{
"in": "path",
"name": "codCliente",
"description": "Código do cliente",
"required": true,
"type": "integer"
}
],
"responses": {
[...]
}
}
},
In OpenAPI 3.x, the parameter type must be wrapped into the schema keyword. The missing schema is what causes the issue with Swagger UI.
"parameters": [
{
"in": "path",
"name": "codCliente",
"description": "Código do cliente",
"required": true,
"schema": { <-----------
"type": "integer"
}
}
],
The syntax without schema (as in your original example) is used in the previous version of the spec, OpenAPI 2.0 (swagger: '2.0').
You can check your OpenAPI definitions for syntax errors using https://editor.swagger.io or other validators.

Why does my browser extension do nothing on page load (except in the toolbox)?

I've been trying to make a Firefox extension. I've had success with doing stuff after a user interaction (like a browser action). But I want my extension to do something without user interaction. But no matter what I do, I can't get anything to happen on page load. Here is my super reduced code:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["test.js"]
}
}
test.js
document.addEventListener("DOMContentLoaded", init);
function init() {
document.body.innerHTML = "Hello world!";
}
What am I doing wrong here? It works in the toolbox, just not anywhere else!
I've also tried adding host permissons like this:
"permissions": [
"*://*.facebook.com/*"
],
Try this:
manifest.json
{
"name": "Test",
"version": "0.1",
"manifest_version": 2,
"background": {
"scripts": ["background.js"]
},
"permissions": ["webNavigation", "*://*.facebook.com/*"]
}
background.js
browser.webNavigation.onDOMContentLoaded.addListener(handleOnDOMContentLoaded, {
url: [{ hostEquals: 'www.facebook.com' }],
});
function handleOnDOMContentLoaded({ tabId }) {
browser.tabs.executeScript(tabId, { file: 'test.js' });
}
test.js
document.body.innerHTML = 'Hello world!';

Open custom url from vscode

I'd like to create a shortcut to open a custom link generated using the selected text from the current editor. So far I tried:
{
"key": "ctrl+enter",
"command": "workbench.action.url.openUrl",
"args": {
"text": "https://www.thesaurus.com/browse/${selectedText}"
},
"when": "editorTextFocus"
},
with no success.
Is it possible?

Jstree - Add nodes to tree by user input (button click)

I have a ASP.NET MVC 4.0 project using JsTree. The JsTree is being populated thought a model that returns a JSON.
Now my problem is this, i have a huge tree that makes the user experience pretty bad. What i need is to load a few items (let'say 20), and have a button that when clicked by the user add's the next 20 records to the tree.
I have been searching in Google JsTree documentation and SO, but i haven't found a example that works for me.
Can anyone help me?
Thanks in advanced.
Ok, some break trought. I kind of got this working. In my view the user input call this function:
function getNextRecords() {
var new_data = { "attr": { "ID": "999999999999", "NodeText": "999999999999" },
"data": "999999999999",
"children": [{
"attr": { "ID": "ACT99", "NodeText": "969994222" },
"data": "969994222 - PPP",
"children": [{
"attr": { "ID": "TRFps800", "rel": "disabled" },
"data": "Voz com unlimited 800 fidelização até 01/11/2019",
"state": "open"
}],
"state": "open"
}], "state": "open"
};
var retDom = $.jstree._reference("#demoTree")._parse_json(new_data, -1, true);
$("#demoTree").jstree("move_node", retDom, -1, "inside", false, false, true);
}
This is working fine, expect that the parse json creates a "ul" instead of a "li" any ideas in how to change that?
OK, i finally got this working, this is the final version of my Function i hope this helps someone.
function getNextRecords() {
var new_data = { "attr": { "ID": "999999999999", "NodeText": "999999999999" },
"data": "999999999999",
"children": [{
"attr": { "ID": "ACT99", "NodeText": "969994222" },
"data": "969994222 - PPP",
"children": [{
"attr": { "ID": "TRFps800", "rel": "disabled" },
"data": "Voz com unlimited 800 fidelização até 01/11/2019",
"state": "open"
}], "state": "open"
}], "state": "open"
};
var ref = $("li ul:first")
var retDom = $.jstree._reference("#demoTree")._parse_json(new_data, ref, true);
$("#demoTree").jstree("move_node", retDom, ref, "first", false, false, true);
}
This add a new child after the first UL.
The second part "load part of the branch and with another load of the same branch
load more" is exactly what i'm trying to do but i have not yet succeeded, is it
possible to have an example?
Such task must be taken care of on server side. Take is this way: jsTree only displays whatever is passed to it. So you make a decision what to load in a first go and you can have a button (to reload the whole tree or a branch only) to load more or replace whatever was loaded. Don't forget the logic has (almost) nothing to do with jsTree.

Resources