I am learning how to make firefox extensions and have gotten totally confused... so I thought I would start from the basics again.
Can you make me (or walk me through creating) a simple skeleton extension that saves "ryan" into sqlite storage, so that it is available even on the browser restart?
From there I think I can start modifying it to run all the different code that exists only in my head... and to answer my own questions :))
Thanks!
Ryan
This is even simpler if you use the Addon SDK.
var storage = require("simple-storage").storage;
if (storage.name) {
console.log (storage.name);
}
else {
console.log ("Storing!");
storage.name = "ryan";
}
This will output "Storing!" the first time it's run, and "ryan" subsequent times.
Related
I am writing tests for a React based web tool. So I want to clear all local storage such as login information etc. before each test. I have majorly worked in Cypress, where this was just a simple command.
cy.clearLocalStorage();
I am now using WebdriverIO and this is the approach that I was trying out (in the test file).
afterEach(() => {
browser.executeScript('window.localStorage().clear()');
});
However, this doesn't seem to be working. Moreover, I would prefer a global solution, something that I don't have to write in each test. Thanks in advance for the help.
From the WebdriverIO Docs:
// remove the storage item for the given key
client.localStorage('DELETE', 'someKey');
// clear the storage
client.localStorage('DELETE');
You can clear localStorage by running this preset function.
You were almost right in your assumption. I'd suggest using official docs to eliminate minor errors.
Instead of executeScript use https://webdriver.io/docs/api/browser/execute.html
localStorage is not a function, see https://developer.mozilla.org/en-US/docs/Web/API/Window/localStorage
So it should be
afterEach(() => {
browser.execute('window.localStorage.clear()');
});
P.S.
Assuming you are using WebdriverIO 5 or above.
So, after a lot of time, we realized the problem.
The cy.clearLocalStorage() cleans only the local storage under the baseUrl definition.
If you would like to open multiple pages, you have to explicit define the clearing in the cy.visit() call, like that:
cy.visit(`subdomain.another.domain`, {
onBeforeLoad(win) {
win.localStorage.clear();
},
});
In this case, the local storage for the exact domain, will be deleted.
I hope, this workaround helps.
I'm attempting to create a collaborative jukebox as a little project to learn Meteor, so apologies for this very high-level noob question.
I need to be able to call the soundcloud SC.stream (see https://developers.soundcloud.com/docs/api/sdks#streaming) function on multiple clients. The template all clients are looking at is binded to a object that looks something like:
room: {
title: "roomname"
currentlyPlaying: {
trackName: "track name"
trackStreamURL: "http://soundcloud/12345"
}
}
I can't seem figure out a way so that when a client, say the admin, sets a new currentlyPlaying to trigger all client to run SC.stream and start the new song.
I'm just not sure what the right meteor features are to use in this scenario, so i'm not looking for a code solution exactly, just a point in the right direction.
Thanks in advance.
Save the currently playing url in a document in a collection. Then use cursor.observe() or cursor.observeChanges() on the client to watch the document with the url in it. Do this inside a Tracker.autorun in block.
When the url changes, stop playing the previous tune and start playing the new one.
See here for documentation on cursor.observe().
Anyone know how to use CertificateWarningHandler in WatiN?
I've got as far as...
IE ie = new IE("https://mysite.aspx");
CertificateWarningHandler cwh = new CertificateWarningHandler(CertificateWarningHandler.ButtonsEnum.Yes);
cwh.HandleDialog(new Window(ie.hWnd));
... which does precisely nothing.
On a more general note, how on earth do you people manage to use this tool? The documentation is nearly useless, and there doesn't seem to be any decent resource online. I must be missing something because it's taken me about half an hour to write 3 lines of code that don't even work.
I'm using something similar to what Saar is using and it works fine (my tests are cross-browser).
//Override security warning in browser
{
if (Browser.Link(Find.ById("overridelink")).Exists)
{
Browser.Link(Find.ById("overridelink")).Click();
Browser.WaitForComplete();
}
else
{
Browser.WaitForComplete();
} //end else
}
I'm not a developer, and I've found that there's plenty of information out there on WatiN and others post code samples and the like that are really helpful. Google is one of my best friends when it comes to finding WatiN help. You'll get the hang of it.
have you tried following already?
ie.DialogWatcher.Add(cwh);
or just
ie.DialogWatcher.Add(new CertificateWarningHandler());
Update: After comment.
Actually this works for me.
further may be following will help
Browser browser = ie;
if (browser.Links.Exists("overridelink"))
{
browser.Link("overridelink").Click();
}
I have a Flex application with multiple modules.
When I redeploy the application I was finding that modules (which are deployed as separate swf files) were being cached in the browser and the new versions weren't being loaded.
So i tried the age old trick of adding ?version=xxx to all the modules when they are loaded. The value xxx is a global parameter which is actually stored in the host html page:
var moduleSection:ModuleLoaderSection;
moduleSection = new ModuleLoaderSection();
moduleSection.visible = false;
moduleSection.moduleName = moduleName + "?version=" + MySite.masterVersion;
In addition I needed to add ?version=xxx to the main .swf that was being loaded. Since this is done by HTML I had to do this by modifying my AC_OETags.js file as below :
function AC_FL_RunContent(){
var ret =
AC_GetArgs
( arguments, ".swf?mv=" + getMasterVersion(), "movie", "clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
, "application/x-shockwave-flash"
);
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
This is all fine and works great. I just have a hard time believing that Adobe doesn't already have a way to handle this. Given that Flex is being targeted to design modular applications for business I find it especially surprising.
What do other people do? I need to make sure my application reloads correctly even if someone has once per session selected for their 'browser cache checking policy'.
I had a similar problem, and ended up putting the SWF files in a sub-directory named as the build number. This meant that the URL to the SWF files pointed to a different location each time.
Ideally this should be catered for by the platform, but no joy there. But this works perfectly for us, and integrates very easily into our automated builds with Hudson - no complaints so far.
Flex says:
http://www.adobe.com/livedocs/flex/2/docs/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001388.html
What I have done is checksum the SWF file and then add that to its url. Stays the same until the file is rebuilt/redeployed. Handled automagically by a few lines of server-side PHP script
here is sample.
function AC_FL_RunContent(){
var ret = AC_GetArgs(arguments, ".swf?ts=" + getTS(), "movie",
"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000",
"application/x-shockwave-flash");
AC_Generateobj(ret.objAttrs, ret.params, ret.embedAttrs);
}
function getTS() {
var ts = new Date().getTime();
return ts;
}
AC_OETags.js is file and it exists html-template several places.
but as my posting said, I am facing another type of problem.
The caching is not done by Flash Player but by the browser, so it's out of Adobe's control. I think you have found a workable solution. If I want to avoid caching I usually append a random number on the URL.
I'm working on a web app (ASP.NET) that has some features that require Microsoft Excel installed on the client. I'd like to disable those features if Excel is not present.
Windows/IE/Excel only solutions are fine. This is not a multi-browser, multi-OS web app.
Any clever JavaScript out there to accomplish this?
No.
You're not allowed to dive into the client machine deep enough to figure out that part. The best you can do is to either assume it is installed, and ponder hard about what happens if it is not, or just ask the user.
You can do something like this, but you'll get all kinds of security warnings:
<script>
var excelInstalled;
try
{
var excel = new ActiveXObject("Excel.Application");
excelInstalled = true;
}
catch(e)
{
excelInstalled = false;
}
alert("excelInstalled: " + excelInstalled);
</script>
Why Excel? What if I have OpenOffice.org instead?
Just warn the user what you're going to send them, mark the link with "Excel file", and let him decide.
function hasOfficePlugin() {
var toCheckExt = ['', '12', '13', '14', '15'], i, n, mt;
for (i = 0, n = toCheckExt.length; i < n; i++) {
mt = navigator.mimeTypes['application/x-msoffice' + toCheckExt[i]];
if (mt && mt.enabledPlugin && mt.enabledPlugin.name) {
return true;
}
}
return false;
}
I've tested the above with Office 11 (2003), and Office 12 (2007), and it seems to work well in Firefox, Safari, Chrome, and Opera. Though it doesn't work in IE, because the navigator.mimeTypes objects in IE is always empty.
It's checking for the existence of an MS Office plugin. I don't know much about this plugin - quite possibly it's not always installed with office... But I think that, if the above returns true, it's a pretty strong signal that Excel is installed. Course it's probably of limited use since it doesn't work in IE, but maybe you can do something with it...
you can not access client information outside of the web browser context, using standard technologies. but I see one of answers is using some ActivX object to detect Excel. anyway these kinds of technologies work only on Internet Explorer on windows. what about Mac? what about other browsers like opera or firefox or chrome on windows?
I think it is better to let the user inform you about this. just ask the user if she has excel installed or not:
var isExcel = window.confirm('dear user if you have Microsoft Excel installed please click on ok, otherwise click on cancel. thank you.');
This is bad idea at start. What ever you are trying to do - reconsider.
If you still insist:
Try to crete ActiveXObject for Excel and then for OpenOffice.
If it fails, redirect to NoExcel.html or send XMLRequest to server.
Also, you can try to find out via JavaScritp if there is XLS file extension handler.
And last, you can install your ActiveX which checks if Excel is installed.
This is for windows. No idea for mac, linux, mobile...
You can bet that any way you make it work will stop working with next hotfix.