extension closing after entering prompt input - javascript

So I've created a chrome extension where it asks for a prompt to rename something, but for some reason it closes the whole extension after submitting the prompt. It still works, just the extension closes every time a prompt is submitted.
The thing is, for some reason, this doesn't happen to everyone. I tested it on a windows computer and the extension stays open, but on my macbook where I code it, it closes the extension.
I can't find any reason this is happening or any other questions similar to this, any help would be appreciated!
code:
var notename = prompt("Enter name:")
var regPattern = /^[\w\-\s]+$/;
var testthing = regPattern.test(notename)
if (testthing==true && notename.length > 0){
chrome.storage.local.set({["note-"+notenumber+"-title"]: notename}, function(){
})
}else{
alert("Invalid name! Only alphanumeric characters allowed.")
}

Related

How do I open an array of PDF files in Illustrator without user confirmation of prompts using javascript/extendscript?

I want to open an array of files in Illustrator without prompts and apply the preference of the page number to open using Javascript.
I've tried setting the PDF open options but that doesn't seem to suppress the prompt. It also doesn't seem to apply the options.
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pDFCropToBox = PDFBoxType.PDFBOUNDINGBOX;
pdfOptions.pageToOpen = 1;
if (file != null) {
var docRef = open(file, DocumentColorSpace.CMYK);
}
When I set "pageToOpen" to 3 it doesn't even pre-select that in the prompt that pops up asking for a choice of which page to open. However I don't want that to pop up at all. I need to open the first page of all the files, get some information and close the files without human interaction.
var pdfOptions = app.preferences.PDFFileOptions;
pdfOptions.pDFCropToBox = PDFBoxType.PDFBOUNDINGBOX;
pdfOptions.pageToOpen = 1;
// Open a file using these preferences
if (file != null) {
var docRef = open(file, DocumentColorSpace.CMYK, pdfOptions);
}
The code above causes an error: "unknown open options found". These are examples from the illustrator programming guide.
I figured it out:
app.userInteractionLevel = UserInteractionLevel.DONTDISPLAYALERTS;
It appears the prompt isn't affected by the preferences but if you turn off the interaction level with that line it respects the pdf open preferences.

Why isn't this picking up commands issued to the console?

In an attempt to prevent clever visitors from cheating the system on my site, I'm trying to secretly record and send to the server anything typed into the browser's command line. The relevant chunk of code is
window.console.command = function (thiscmd) {
alert('thiscmd = ' + thiscmd); // test
if (SG.consoleCommands) SG.consoleCommands += thiscmd;
}
but the alert isn't working. I'm using Google Chrome, but tried in IE as well.
Relevant fiddle: Go to http://jsfiddle.net/63cL1qoe/ and typed var x = 69; in the console and click enter. Nothing happens.
What am I missing?

html5 make a phonecall in ios

I make a website which can input a telephone number and click a button can make a phonecall with this number. As you do that, it will jump to a telephone app to call someone that you just inputed number(this maybe the browser s work). When hang up the phone, it will jump back to the website.
Here is the question, when come back to the website, how can I know about had hanged up the phone and to display information in the website? Can I get the message use with JS? or it have some event in ios? thank you!
function callto(){
var number = document.getElementById("telnumber").value;
if( number == "" )
{
number = "xxxx";
document.getElementById("telnumber").value = "xxxx";
}
window.location.href = "tel:" + number;
}
You can't, this information is not available. Not even in the native iOS SDK.

CasperJS- Register on a site and validate the mail sent on Gmail -for both slimer and phantom-

Edit : this is the windows behaviour, with linux it just fails.
First, if you succeeded navigate on gmail with casper (without random waiting time -from 20sec to 5min-), please tell me.
I want to register on our site, then validate my registration automatically with Gmail (an entire register step). Did someone do that before?
I have no problem to register, and I can login on my mailbox (Gmail) but after i have some troubles to navigate and validate my registration in Gmail, and i observe different behaviors between phantomJS and slimerJS.
In phantom it will work (without special commands), but it may take until 5 minutes before pass in the next step (waitForSelector). And with slimerjs it just stays stuck on the mailbox page.
EDIT : A strange thing : if i click manually (slimer) on a link which opens a popup, it stops being blocked and my navigation continues, it's like it can't detect the end of the step itself and can't perform the waitFor after the submit click without another interaction. Is it a refresh/reload problem?
Try that to see yourself :
casper.thenOpen('https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en', function(){
this.sendKeys("input#Email","your mail");
this.sendKeys("input#Passwd","your password");
this.click("input#signIn.rc-button-submit");
console.log(this.getCurrentUrl());
this.waitForSelector(".aeF",function(){//fail with linux -> timeout
this.test.pass("ok"); //windows -> stuck in slimer, several times in phantom
this.test.assertExists(".T-I.J-J5-Ji.T-I-KE.L3","Gmail Home ok");
console.log("url "+this.getCurrentUrl());
});
And i don't get any timeOut error. In slimerjs it just keeps the page opened.
If i do a waitForPopup instead of a waitForUrl, i have the error (timeout -> did not pop up), so why does a waitForUrl/waitForSelector... stay stuck ? I tried --web-security=no,--ignore-ssl-errors=true commands too (not linked but i tried --output-encoding=ISO 8859-1 too which doesn't work).
Here the differences between phantom and slimer (doc) :
http://docs.slimerjs.org/0.8/differences-with-phantomjs.html
(useless in this issue i think)
Well, we finally found a way to do it : the problem is by default gmail loop on ajax requests, to check some new mails, etc... see Page polls remote url, causing casper to block in step.
Fortunately google proposes a way to avoid that, using the simplified HTML version (you can for example use a special gmail address for your tests using this version) :
That way the script works as it should.
Bonus :
/*
* Click on an element specified by its selector and a part of its text content.
* This method resolves some problem as random space in textNode / more flexible too.
* Need to fix one bug though : when there is a tag in textContent of our selector.
*/
casper.clickSelectorHasText = function (selector, containsText){
var tmp = this.getElementsInfo(selector)
,i
,l
,bool=false
;
for (i=0,l=tmp.length;i<l; i++){
if(tmp[i].text && tmp[i].text.indexOf(containsText)!==-1){
this.clickLabel(tmp[i].text);
bool=true;
break;
}
}
casper.test.assert(bool, "clickSelectorHasText done, text and selector found -> click selector " + selector +" which contains text " + containsText);
};
casper.thenOpen('https://accounts.google.com/ServiceLogin?service=mail&continue=https://mail.google.com/mail/&hl=en', function scrapeCode(){
//log in
this.sendKeys("input#Email","your email");
this.sendKeys("input#Passwd","your password");
this.click("input#signIn.rc-button-submit");
//wait to redirect to our mailbox
this.waitForSelector("form[name='f']",function(){
//check main block
this.test.assertExists("form[name='f']","Gmail Home ok");
this.test.assertSelectorHasText("span", "Your gmail title message");
this.clickSelectorHasText("font", "one string which appears in font tag");
//wait inscription message appears
this.waitForSelector("div.msg",function(){
this.test.assertSelectorHasText("a","the message which activates your account--> in <a>");
});
})
//validate our account
.then(function(){
this.clickLabel("the message which activates your account--> in <a>");
this.waitForPopup(/mail/, function(){
this.test.pass("popup opened");
});
this.withPopup(/mail/, function(){
this.viewport(1400,800);
this.test.pass("With Popup");
//wait something on your website (for me selector .boxValid)
this.waitForSelector(".boxValid", function(){
/*
* Here your code after validation
*/
});
});
})
It might be possible to do it with normal gmail using event, see resource.received.

Chrome back button terminates upload stream unexpectedly

I'm providing users form-based file uploads (one at a time) with ajax updates/progress bars. I want to give them a heads up if they navigate away that any current upload will be canceled. The following code achieves that goal except in Chrome (v.18). If you click the back button in Chrome the file upload stream is immediately terminated, throwing a org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly from the commons.fileupload library.
I couldn't find any information specific to this issue, but does anyone have any idea if this is something I'm just going to have to live with for now? Thanks.
Edit: I should add that Chrome does still shows the "Leave page" dialog, but at that point the upload is already stopped so the answer won't affect it at all. Clicking a link in Chrome does not stop the upload, and behaves as expected.
window.onbeforeunload =
function(event) {
if (upload_in_progress) {
var msg = "You are uploading a file." +
"If you leave this page the upload " +
"will be cancelled.\n\nLeave page?";
var event = event || window.event;
if (event) { event.returnValue = msg; }
return msg;
}
};
In Chrome and Safari functions attached to beforeunload event must always return string value (message displayed to user).

Categories