I'm able to run this extension somehow:
https://github.com/mdn/webextensions-examples/tree/master/beastify
On clicking the Browser Icon popup/choose_beast.js is invoked.
Can somebody tell me why this code(placed in the top of popup/choose_beast.js) is generating exception:
try{
var ss = require("sdk/simple-storage");
ss.storage.myArray = [1, 1, 2, 3, 5, 8, 13];
}catch(e){
alert('exception');
console.log(e);
}
Here is the relevant entry in the manifest.json:
"browser_action": {
"default_icon": "icons/beasts-32.png",
"default_title": "Beastify",
"default_popup": "popup/choose_beast.html"
}
What is the way I can store the data in this popup html so that I can retrieve anytime in the content script?
Also under which context is this page choose_beast.html running? Background, page script or content script?
A web-extension should be using storage API for this purpose.
Here is an example usage.
Related
I have a Table in the google docs and want to change its alignment to -0.71 but i do not see any Python API to change table properties. This can be done easily using following UI on google UI (as shown below):
I also tries looking at following requests but could not find it:
updateTableColumnProperties
updateTableCellStyle
For debugging, i created a doc with mentioned alignment and tried dumping JSON of it. But i do not see alignment keyword in the JSON.
Thanks #jescanellas for reply.
I found a hack, this may not be the best solution but works.
1) Update paragraph style and set the indentation, alignment as required. Here the start_idx is the index where table needs to be created.
request = [{
'updateParagraphStyle': {
'paragraphStyle': {
'namedStyleType': 'HEADING_5',
'direction': 'LEFT_TO_RIGHT',
'alignment': 'START',
'indentFirstLine': {
'magnitude': -51.839999999999996,
'unit': 'PT'
},
'indentStart': {
'magnitude': -51.839999999999996,
'unit': 'PT'
},
},
'fields': '*',
'range': {
'startIndex': start_idx,
'endIndex': end_idx
}
}
}]
2) Create the table, it will get created at new indented place.
request = [{
'insertTable': {
'rows': 1,
'columns': 1,
'location': {
'segmentId':'',
'index': start_idx
}
},
}]
It's not currently possible to do so. You can create a Feature Request for the Docs API, and you can also subscribe to this one for Apps Script by clicking on the star next to the Issue number to give more priority to the request and to receive updates.
In case of the second request being implemented, you could call the script from the command line using Clasp.
With the new firefox webextensions: Is there a way to save the current page (or a part of it) as html (or text) to disk? If not, how are the chances, such an API will be implemented in the future?
I didn't find any suitable API and appreciate any help.
Regards
There are probably several ways to do this. The following will get you started. It saves the webpage in the currently focused tab in the active window to the browser's default downloads path. The file name is set to 'samplePage.html' (you can change that by modifying the filename value in the downloads.download() options; or you can remove that field entirely and leave it to the default naming).
You will need to store icon images in your webextension package for the user to be able to click on. Also, be sure to navigate to a webpage you want to save before you try to use the webextension; webextensions are not active on the Firefox about:debugging page.
manifest:
{
"name": "SavePage",
"version": "1.0",
"description": "Clicking browser icon saves page html",
"manifest_version": 2,
"icons": {
"48": "icons/clickme-48.png"
},
"permissions": [
"tabs",
"activeTab",
"downloads"
],
"browser_action": {
"default_icon": "icons/clickme-32.png"
},
"background": {
"scripts": ["background.js"]
}
}
background script:
/* BACKGROUND SCRIPT
Clicking on browser toolbar button saves the webpage in the
current tab to the browser's default downloads path with a
filename of "samplePage.html". The "tabs" and "downloads"
permissions are required.
*/
browser.browserAction.onClicked.addListener((tab) => {
var currentUrl = tab.url;
function onStartedDownload(id) {
console.log(`Started to download: ${id}`);
}
function onFailed(error) {
console.log(`Something stinks: ${error}`);
}
var startDownload = browser.downloads.download({
url : currentUrl,
filename: 'samplePage.html'
});
startDownload.then(onStartedDownload, onFailed);
});
An alternative approach might be to try to save the webpage to local storage rather than to disk. I have not explored that option.
These pages may be helpful:
downloads.download()
browserAction.onClicked
There may be security risks in giving a webextension these permissions. You will have to weigh the risks for your own usage pattern.
After following the steps in this thread:
Google Sign-In for Websites and Angular 2 using Typescript
I could successfully log in with Google after y navigate other component with router.navigate(). I used the logout button like this:
signOut() {var auth2 = gapi.auth2.getAuthInstance();
auth2.signOut().then(x=> {}).then(this._router.parent.navigate('Login'] ));
This last command sent me again to the login component, the difference is, that if i tried to log in again nothing happens (the on success function is not being called), although inside the google developer console it shows that the token is being retrieved.
access_token: "ya29.pgKa3wixEFbsLB-yUW2Mf3s8YvasRoM5javqTc9TxQgnW- WUdxGD0CYyZj7p107e9w"
expires_in: 3600
Hope you can help me.
PD: the code that is making the login process right now:
gapi.signin2.render(
this.googleLoginButtonId,
{
"onSuccess": this.onGoogleLoginSuccess,
"scope": "profile",
"theme": "dark",
"width": 240,
"height": 50,
"longtitle": true,
'onfailure': this.onGoogleFailure
});
Thanks in advance.
I want to create an extension for Google Chrome, and it will be real simple.
I will have a database on my website's server, it will check if a URL is in the "blacklist" table, and warn the user if it is.
But I don't know where to start. I tried putting all the files on my web server, and changin the manifest.json file as such:
(changed the "default_popup" line)
{
"manifest_version": 2,
"name": "My Extension",
"description": "This extension warns you if you are trying to open a blacklisted URL",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "http://www.mysite.com/my_extension/popup.html"
},
"permissions": [
"https://secure.flickr.com/"
]
}
Note : this file resides on my computer, I load it from the "Extensions" menu of Chrome.
but when I tried to install this extension, I got the error :
This web page could not be found:chrome-extension://hgfdjnsakhkijfmdnadmlacgjggggkpf/http://www.mysite.com/my_extension/popup.html
Instead of trying to hard code it in the manifest file, try putting something like this in a background page:
chrome.browserAction.setPopup({popup: "http://www.mysite.com/my_extension/popup.html"});
However, it may not be possible to specify an external popup page at all.
Nevertheless, it would be better to include the popup in the extension files and then get just the data from your server.
I am very new to js and chrome extentions and am trying to make a chrome extension that gets the current tabs url and adds a '&flash=on' at the end. my code doesn't seem to want to work right
manifest.json
{
"name": "FlashOn Chrome",
"version": "0.1",
"description": "Changes default to flash player",
"permissions": [
"tabs"],
"content_scripts": [
{
"matches": ["http://www.stream.com/*"],
"js": ["script.js"]
}
]
}
script.js
function updateUrl(tab){
var currentURL = tab.url
var newurl = currentURL.replace(currentUrl + "&flash=on");
chrome.tabs.update(tab.id, {url: newurl});} chrome.browserAction.onClicked.addListener(function(tab) {updateUrl(tab);});
its for a streaming site that has html5 video and flash video but the flash is only accessible by adding the &flash=on to the end of the url
Not sure what you're trying to accomplish here: are you trying to change the location of the page, from the current URL to the URL with &flash=on` added on to it?
Also -- the script here seems to be incomplete: could you provide a complete script?
One obvious problem: you've got currentURL and currentUrl:
var newurl = currentURL.replace(currentUrl + "&flash=on");
Note that in a content script you can get and set the URL of the page with location.href.