What happens when we use localStorage in a Chrome extension ?
localStorage.setItem('foo', 'bar');
foo is stored in its respective localStorage for every website we visit ?
So 10 different website visits mean 10 versions of foo ?
Is there a way to store foo globally ?
If you use chrome.storage.local, you can store data "globally" for the entire extension. But only the extension will have access to it, websites will not.
https://developer.chrome.com/docs/extensions/reference/storage/
Related
My Angular application URL structure is as below:
Domain/clientCode/*
And the backend API which is a Node application is setting cookie as below:
Fetch clientCode from the URL and set cookie as:
response.cookie('client', clientCode, { httpOnly: true });
Now the problem is When we open Multiple client URIs in different browser tabs (Chrome) in Quick succession, all the tabs get same value for client cookie. If we open different client tabs once pervious one gets loaded then cookie is setting properly for each tab.
Example:
When we open below URLs in different tabs in Chrome in quick succession:
Domain/ABC/*
Domain/BCD/*
Domain/DEF/*
Domain/XYZ/*
The client cookie has same value for multiple tabs(We want it to be different for each tab as per the clientCode in the URL).
I know that cookies are saved for a domain and doesn't consider other values in the URL but Its working fine when we open multiple URLs with little bit of gap.
Thanks in advance.
This is happening because you are setting a static cookie for your domain. You need to set dynamic cookies to avoid the issue.
For example: You may set the cookie name for the username = 'Michelle' with random dynamic values like Michelle_456900234. For each login session, you will have a dynamic value associated with it. While retrieving the value just find the substring username.
I have created a chrome extension for generating passwords and outputting the phonetic version as well.
Basicly the extension creates the password and displays it in one DIV and the phonetic version in another, so if password was 'ac3', password DIV would show 'ac3' and phonetic DIV would show 'Alpha, Charley, Three'.
The problem is that as soon as I click outside the extension popup it disappears and I loose the current password.
My first attempt to sort this was to use chrome.storage.local.set after creating the password and then re-populating the password DIV via chrome.storage.local.get when you click on the extension again, this works great, but the data is available from any tab within the browser (even separate windows).
I understand that storing the password in any way is insecure, but wanted to find a way to limit the data stored to the current tab rather than globally.
I haven't found a way to keep the extension popup displayed to allow a user to copy/paste both DIVs.
Anyone got any pointers?
Also anyone able to point me in the direction of wiping the local storage value after a set amount of time? Just to make things slightly more secure.
This extension is used mainly for admin work, where you need to create a new password for a user, copy/paste it into a portal and then SMS/Email the password to the end user.
Data stored in chrome.storage is only available to your own extension, so it's not any less secure than any other way of storing it.
Just store it via chrome.storage.local.set() and then delete it a few minutes later, if unused. You'll have to set a deletion mechanism in background.js via chrome.runtime.sendMessage or chrome.alarms
I had also tried sessionStorage in the popup, but sadly it's lost as soon as the popup is closed. Same goes for history.replaceState.
I need to transfer files from one location to another, and the destination folder should be the user's download location.
I was wondering if it's possible to obtain the browser's download location using Node JS or simply Javascript. I need a way to do it that works for all systems and browsers possibly.
Up to now I was just typing the location manually, but I need an automatised way of doing it of course!
At least on Windows, this will normally be %USERPROFILE%/Downloads.
In NodeJS, you could write:
var downloadFolder = process.env.USERPROFILE + "/Downloads";
It is not possible in node.js to know the user's download location unless you ask the user to specifically type it into some input field in a form. That location is purely a user agent setting that is purposely not disclosed to any server or web page for security reasons.
Furthermore, the server or webpage cannot influence where a file might be saved by the browser on the user's local hard drive anyway (again for security reasons) so there's nothing useful a server can do with that information anyway unless you happen to be running a server that is on the same machine as the browser. If you're working in that type of controlled environment, then perhaps you could use a browser extension that does have access to some of these kinds of things.
I have an extension that need to wirte something in localStorage and clean (or set a special value) when user close the browser.
This link showing that there is no way to detect when the browser is closed.
So any suggestion?
If you're using a persistent background page, use sessionStorage instead of localStorage to save variables.
If you're using an event page, then you need to maintain some kind of session identifier, and prefix your value or key with this identifier. This identifier can be stored in localStorage and must be refreshed during the chrome.runtime.onStartup and chrome.runtime.onInstalled events.
How it is possible to move cookie from one browser to another? This must be done through the browser options
It sounds like you would like to be able to set a cookie in one browser (such as Google Chrome) and be able to access it from another browser (such as IE6).
If that is the case, check out evercookie (a very beefy solution).
If you want something more lightweight, you could try Adobe Flash cookies.
An easy way to see flash cookies in action:
In one browser open a YouTube video.
Change the volume.
Open a YouTube video in another browser.
You will be able to see that the volume has been remembered between browsers.
If you're trying to manually copy cookies between browsers, this JavaScript bookmarklet may be useful - it allows you to access and modify the cookies of the current domain; this means you could run it in one browser, copy the cookies to clipboard, then run in another browser and paste.
Note that some apps may store browser-specific data (or flags) in cookies (or related components, like sessions), which may lead to strange behavior (e.g. "this-cookie-was-set-for-IE6=1, enable broken-browser-workarounds").