Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Skandranon
Sep 6, 2008
fucking stupid, dont listen to me
You could maybe try something like a WebWorker. It will run a separate .js file in a separate thread, and has no access to the DOM or a lot of other things, but can communicate with the main thread (and thus, the DOM) via postMessage.

Adbot
ADBOT LOVES YOU

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

Bruegels Fuckbooks posted:

The requirement for making it so the script interacts with the widget means you should probably look into having the widget render on the server with the user script executing on the server as well (like using node / Rhino) - some of the codepad utilities will run the javascript in an iframe, but since the script needs to interact with the widget, it'll be nearly impossible to lock everything down client side.
The script can interact with the widget via a server-side API as well; you can stream push updates down a WebSocket. But iframes are janky as poo poo and I can't believe the working groups didn't add any sandboxing to Web Components.

Munkeymon
Aug 14, 2003

Motherfucker's got an
armor-piercing crowbar! Rigoddamndicu𝜆ous.



Subjunctive posted:

Oh, I meant at the call site, sorry.

:doh: nah, I should have realized what you meant from the context

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Sandboxing is what caja does, it works well.

German Joey
Dec 18, 2004

Subjunctive posted:

Sandboxing is what caja does, it works well.

oh, this looks perfect! Looks like it works how I envision something like this should work...

edit: except for all of their demos being broken...

German Joey
Dec 18, 2004

Skandranon posted:

You could maybe try something like a WebWorker. It will run a separate .js file in a separate thread, and has no access to the DOM or a lot of other things, but can communicate with the main thread (and thus, the DOM) via postMessage.

that's not a bad idea. I googled a bit along these lines and found this:

https://github.com/asvd/jailed

Which seems like I could do something with. I think what I'd want to do is instantiate the user code inside a wrapper, which would provide with an API that shadowed that of my widget. However, rather than operating on the widget directly, the user would actually be invoking the wrapper, which would use postMessage to communicate a command to the wrapper around the widget. Likewise, any events generated by the widget would themselves invoke postMessage to communicate a command to the worker, which would then invoke a cooresponding worker event.

This seems a lot simpler than using caja, and I bet it would be a lot faster too... I'm already worried about my app being very resource-intensive on the server side, even without needing to worry about processing crap for every little UI interaction.

edit: Oh I see now, this is exactly what jailed does already! I just need to provide a wrapper to jailed's application.remote object to hide that interface from the user.

German Joey fucked around with this message at 23:25 on Nov 5, 2015

Random Hero
Jun 4, 2004
I could sure go for a Miller High Life...
I am running into some issues with a Node.js function I am trying to run on AWS Lambda and need some help. I have a Lambda function wired up to receive events on an S3 bucket where I have gzipped log files sent to using Logrotate. When the files reach S3, Lambda kicks in and executes a Node.js function that retrieves the object from S3 and gunzip's it and attempts to process the log entries. The problem is the gzip actually contains directories with the logfile(s) nested and I cannot figure out how to process the Buffer returned from the zlib.gunzip operation with the folders involved.

Is there a way to do this in memory, or should I be getting the object from S3, writing it to the disk, gunzip there and then use fs to read the contents of the files in the directories? Memory would be ideal but if writing it to the disk is my only option, that is fine. Thanks and let me know what else could help here.

obstipator
Nov 8, 2009

by FactsAreUseless
I saw this today: http://tonicdev.com
Its basically jsfiddle or codepen but for nodejs. I haven't looked at it much yet, but seems like a really awesome way to test out npm modules without installing anything. I have no idea how it could possibly be secure though.

Tigren
Oct 3, 2003
Hey guys, I'm trying to learn Javascript and I'm making a an API call using basic auth. When using Postman, I can get a response no problem. When copying that same Postman request into my app, I get the following response:

quote:

XMLHttpRequest cannot load https://api.routexl.nl/tour. Response for preflight has invalid HTTP status code 401

Setting withCredentials to true gives me an error like this:

quote:

XMLHttpRequest cannot load https://api.routexl.nl/tour. Response to preflight request doesn't pass access control check: A wildcard '*' cannot be used in the 'Access-Control-Allow-Origin' header when the credentials flag is true. Origin 'http://127.0.0.1:8000' is therefore not allowed access

I'm led to believe this is a CORS issue, but I'm not entirely sure how to fix it or if I even CAN fix it. What's the correct way to go about this? Thanks for the help.

Tigren fucked around with this message at 19:06 on Nov 7, 2015

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.
Yeah, you need CORS enabled on the server and your client request.

Look at http://enable-cors.org for info relevant to your server, there is middleware available for most frameworks

If you don't have control over the server you're poo poo out of luck, you'll then need the JavaScript to run in the context of that domain in order to avoid CORS checks. This is a security feature so you're not going to find a loophole for avoiding CORS.

Tigren
Oct 3, 2003

Maluco Marinero posted:

Yeah, you need CORS enabled on the server and your client request.

Look at http://enable-cors.org for info relevant to your server, there is middleware available for most frameworks

If you don't have control over the server you're poo poo out of luck, you'll then need the JavaScript to run in the context of that domain in order to avoid CORS checks. This is a security feature so you're not going to find a loophole for avoiding CORS.

That's the conclusion I came to. Unfortunately, I don't control the server. Thanks for the help.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
There's a business idea in building a proxy that flat out ignores CORS and shoves all requests through it.

Impotence
Nov 8, 2010
Lipstick Apathy

Suspicious Dish posted:

There's a business idea in building a proxy that flat out ignores CORS and shoves all requests through it.

npm install corsproxy

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
CPaaS

corsproxy as a service

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

There's a business idea in building a proxy that flat out ignores CORS and shoves all requests through it.

Doesn't give you the user's request context (cookies, auth, certs), alas.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe

Subjunctive posted:

Doesn't give you the user's request context (cookies, auth, certs), alas.

why can't you proxy those through

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

Suspicious Dish posted:

why can't you proxy those through

Because they only get sent to the appropriate domain, which isn't corsaas.com.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Oh, I was imagining you were talking about the page host's cookies, not the target host's cookies (so document.cookie is sufficient).

Auth seems irrelevant -- I don't think browsers save auth between sessions, so a prompt for auth doesn't seem too out of place (you could convince users to re-enter it).

And does anybody use client-side certs yet? OK, OK, outside of that one weird corporate site you encountered once that also required a custom ActiveX plugin.

Subjunctive
Sep 12, 2006

✨sparkle and shine✨

document.cookie doesn't convey httponly cookies, of course. by certs I mean validation of the server's cert against the client's configuration (roots installed, revocations seen), but apparently in Europe client certs are actually a thing for government sites? We used to get bugs filed.

Suspicious Dish
Sep 24, 2011

2020 is the year of linux on the desktop, bro
Fun Shoe
Sure, but the whole reason for a CORS proxy is to work around a security policy. So of course our corsaas wouldn't validate any certificates, ever, and it would just serve up over plain HTTP, sslstrip style.

my effigy burns
Aug 23, 2015

IF I'M NOT SHITPOSTING ABOUT HOW I, A JUNIOR DEVELOPER IN JAVASCRIPT KNOW EVERYTHING THERE IS TO KNOW, PLEASE CHECK TO BE SURE MY ACCOUNT WAS NOT COMPROMISED BY A CLIENT-SIDE BOTNET, TIA
If you're on a mac you should be able to do something like the below to disable the chrome security stuff:
code:
 open /Applications/Google\ Chrome.app/ --args --disable-web-security  --allow-file-access-from-files 


But honestly, the easiest solution (if you're not dependent on someone else's lovely api) is to just spin up a server. An express server is like 5 lines, but if that's too much for you, python comes with a one-liner you can run from the command prompt. Just run it from wherever your index.html is. You don't need to know any python at all, just get it installed and you can do this from the terminal:

code:
 python -m SimpleHTTPServer 3000 

my effigy burns fucked around with this message at 23:47 on Nov 7, 2015

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

Suspicious Dish posted:

And does anybody use client-side certs yet? OK, OK, outside of that one weird corporate site you encountered once that also required a custom ActiveX plugin.
My company used to use Lotus Notes, and then the announcement went out that we were going to use gmail. It was great - we could use it on our phones, just use it on any web browser. It worked pretty well for 4 years.

Then they decided Gmail was too open.

Solution:

1. Instead of logging into gmail, you log into some external provider.
2. User needs client side certificate and activex control to log in, and can no longer go directly to gmail, but has to go through some weird website, which requires typing in the concatenation of your company id and employee id plus your password to log in.
3. You need to install a bunch of weird bullshit to get gmail on a phone to work but that's OK because you need authorization from someone director level or higher to get it on your phone.

It loving sucks. I can't figure out how to have Fiddler open and check my email at the same time, or get Gmail to work with loving google chrome.

geeves
Sep 16, 2004

Bruegels Fuckbooks posted:

My company used to use Lotus Notes, and then the announcement went out that we were going to use gmail. It was great - we could use it on our phones, just use it on any web browser. It worked pretty well for 4 years.

Then they decided Gmail was too open.

Solution:

1. Instead of logging into gmail, you log into some external provider.
2. User needs client side certificate and activex control to log in, and can no longer go directly to gmail, but has to go through some weird website, which requires typing in the concatenation of your company id and employee id plus your password to log in.
3. You need to install a bunch of weird bullshit to get gmail on a phone to work but that's OK because you need authorization from someone director level or higher to get it on your phone.

It loving sucks. I can't figure out how to have Fiddler open and check my email at the same time, or get Gmail to work with loving google chrome.

That is loving insane. Was two-factor not an option with Gmail? For a company to be ISO-something-security compliant, you just need two factor and password changes every 3? months I believe. I've worked in places that required security clearances and even then there is nothing as insane as that.

Edit: Sounds like your company got a bunch of FUD as a sales pitch to buy just another layer of "protection" which is just another places where employee information is held by yet another company.

Marx Headroom
May 10, 2007

AT LAST! A show with nonono commercials!
Fallen Rib
I have a beginner nodejs question. The following file is chatserver.js, it's supposed to let you telnet into localhost and type messages back and forth.

I don't understand how the parameters are being passed to the listeners in the chatServer.on() parts. How does the event emitter know which object to pass into the event listener as the 'client' parameter for the 'connection' event? Same goes for the 'data' parameter in the 'data' event.

code:
var net = require('net')

var chatServer = net.createServer(),
    clientList = []

  chatServer.on('connection', function(client) {
  client.name = client.remoteAddress + ':' + client.remotePort
  client.write('Hi ' + client.name + '!\n');

  clientList.push(client)

  client.on('data', function(data) {
    broadcast(data, client)
  })

})

function broadcast(message, client) {
  for(var i=0;i<clientList.length;i+=1) {
    if(client !== clientList[i]) {
      clientList[i].write(client.name + " says " + message)
    }
  }
}

chatServer.listen(9000)
Couldn't the emitter pass basically anything in there? How do I know that something usable is being passed? How does the emitter know that it needs to pass in the data it receives from the socket? How does the emitter know that a 'data' event means it should send something my code can broadcast? Is the event emitter passing a whole truckload of arguments but my code (as written) only cares about the first one?

Impotence
Nov 8, 2010
Lipstick Apathy
i think part of it might be indentation a bit:

code:
var net = require('net')

var chatServer = net.createServer(),
    clientList = []

chatServer.on('connection', function(client) {
    client.name = client.remoteAddress + ':' + client.remotePort
    client.write('Hi ' + client.name + '!\n');

    clientList.push(client)

    client.on('data', function(data) {
        broadcast(data, client)
    })

})

function broadcast(message, client) {
    for (var i = 0; i < clientList.length; i += 1) {
        if (client !== clientList[i]) {
            clientList[i].write(client.name + " says " + message)
        }
    }
}

chatServer.listen(9000);
client.on is within the connection {}

necrotic
Aug 2, 2005
I owe my brother big time for this!

Mr. Jive posted:

Couldn't the emitter pass basically anything in there? How do I know that something usable is being passed? How does the emitter know that it needs to pass in the data it receives from the socket? How does the emitter know that a 'data' event means it should send something my code can broadcast? Is the event emitter passing a whole truckload of arguments but my code (as written) only cares about the first one?

All of the parameters for each event will be documented. Because its JS the only "guarantee" you have on the arguments is the documentation (or reading the code lol).

fantastic in plastic
Jun 15, 2007

The Socialist Workers Party's newspaper proved to be a tough sell to downtown businessmen.

Mr. Jive posted:

I have a beginner nodejs question. The following file is chatserver.js, it's supposed to let you telnet into localhost and type messages back and forth.

I don't understand how the parameters are being passed to the listeners in the chatServer.on() parts. How does the event emitter know which object to pass into the event listener as the 'client' parameter for the 'connection' event? Same goes for the 'data' parameter in the 'data' event.

code:
var net = require('net')

var chatServer = net.createServer(),
    clientList = []

  chatServer.on('connection', function(client) {
  client.name = client.remoteAddress + ':' + client.remotePort
  client.write('Hi ' + client.name + '!\n');

  clientList.push(client)

  client.on('data', function(data) {
    broadcast(data, client)
  })

})

function broadcast(message, client) {
  for(var i=0;i<clientList.length;i+=1) {
    if(client !== clientList[i]) {
      clientList[i].write(client.name + " says " + message)
    }
  }
}

chatServer.listen(9000)
Couldn't the emitter pass basically anything in there? How do I know that something usable is being passed? How does the emitter know that it needs to pass in the data it receives from the socket? How does the emitter know that a 'data' event means it should send something my code can broadcast? Is the event emitter passing a whole truckload of arguments but my code (as written) only cares about the first one?

The code creates a server as the variable chatServer, the chatServer.on function accepts two arguments, an event and a listener. The event is the string 'connection' and the listener is that function(client) stuff, which is a callback. Because node is async, everything in the callback gets evaluated immediately. Callbacks are one of the main ways of establishing flow control in node, for better or for worse.

It creates an object "client", gives it a name property, writes "Hi, (name)", pushes it to an array of connected clients, and then sits around waiting for data. The data is also a callback and just gets stuffed into the broadcast function, which writes it to everyone in the clientList array.

So to hopefully address your questions:

Yes, it can do basically anything in the listener, but what it's doing is defined by your code.

Hopefully you know something's usable because you wrote usable code.

The code starts a data stream; in the on data event handler, "data" is just a parameter name for whatever the chunk of input is that gets passed to the callback.

It knows to broadcast it because the callback runs the broadcast function, which tells it to loop through the client list array and write the data to all of them.

I don't think this code is passing a whole truckload of arguments to anything, but if somehow you tried to execute, say, broadcast(data, client, foo, bar, baz), then javascript's just going to ignore the excess argument.

Marx Headroom
May 10, 2007

AT LAST! A show with nonono commercials!
Fallen Rib

Tao Jones posted:

Hopefully you know something's usable because you wrote usable code.

Thanks, this in particular helps.

necrotic posted:

All of the parameters for each event will be documented. Because its JS the only "guarantee" you have on the arguments is the documentation (or reading the code lol).

Am I understanding this documentation correctly in that the bullet point is the thing that will be passed as an argument when the listener is called? So in this case, the 'net' event emitter creates an instance of 'net.Socket' upon a 'connect' event and passes that as the first argument to the listener?

necrotic
Aug 2, 2005
I owe my brother big time for this!

Mr. Jive posted:

Thanks, this in particular helps.


Am I understanding this documentation correctly in that the bullet point is the thing that will be passed as an argument when the listener is called? So in this case, the 'net' event emitter creates an instance of 'net.Socket' upon a 'connect' event and passes that as the first argument to the listener?

Correct. The format for their documentation of event callbacks is piss poor, but at least it exists I guess...

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Is it possible to do very RAM intensive computations in google chrome? I have a script that I fully expect to use multiple GB of ram, but it can only allocate up to about 1.5GB before chrome gives up with an "Aw Snap", even though I still have 8-10GB free and on 64bit system. The aw snap page is supremely unhelpful and only suggests that i close other tabs to free up RAM.

German Joey
Dec 18, 2004
What the hell are you doing that needs multiple GB of RAM, and why are you doing it in javascript?

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

German Joey posted:

What the hell are you doing that needs multiple GB of RAM, and why are you doing it in javascript?

CSG CAD stuff, for fun

http://openjscad.org

e: it doesn't normally need GBs of ram but i wanted to render a specific very high detail script

peepsalot fucked around with this message at 12:05 on Nov 15, 2015

Bruegels Fuckbooks
Sep 14, 2004

Now, listen - I know the two of you are very different from each other in a lot of ways, but you have to understand that as far as Grandpa's concerned, you're both pieces of shit! Yeah. I can prove it mathematically.

peepsalot posted:

Is it possible to do very RAM intensive computations in google chrome? I have a script that I fully expect to use multiple GB of ram, but it can only allocate up to about 1.5GB before chrome gives up with an "Aw Snap", even though I still have 8-10GB free and on 64bit system. The aw snap page is supremely unhelpful and only suggests that i close other tabs to free up RAM.

Are you on windows? 32-bit processes will crash when they hit the virtual size limit on windows. You should try using 64-bit chrome.

peepsalot
Apr 24, 2007

        PEEP THIS...
           BITCH!

Bruegels Fuckbooks posted:

Are you on windows? 32-bit processes will crash when they hit the virtual size limit on windows. You should try using 64-bit chrome.

I am on linux w/ 64bit chrome

Maluco Marinero
Jan 18, 2001

Damn that's a
fine elephant.

peepsalot posted:

I am on linux w/ 64bit chrome

Have a look around in chrome://flags

You might be able to find some settings that let you tune V8 (the JavaScript engine)

German Joey
Dec 18, 2004

peepsalot posted:

CSG CAD stuff, for fun

http://openjscad.org

e: it doesn't normally need GBs of ram but i wanted to render a specific very high detail script

fairly cool!

edit: sites like this always make me feel warm and glowing about how amazing the potential of the web is, but then when I start developing in Javascript again it doesn't take long for me to degenerate back into a frothing, furious mess. :xd:

German Joey fucked around with this message at 21:33 on Nov 15, 2015

Mostly Sober
Nov 27, 2014
[img][/img]
Hi, I've made a simple little hobby API project using node and express.

I'm fairly new to the node ecosystem and am looking for a lightweight unit testing framework I can use; any suggestions? Thanks!

obstipator
Nov 8, 2009

by FactsAreUseless

Mostly Sober posted:

Hi, I've made a simple little hobby API project using node and express.

I'm fairly new to the node ecosystem and am looking for a lightweight unit testing framework I can use; any suggestions? Thanks!

http://mochajs.org is good

Lumpy
Apr 26, 2002

La! La! La! Laaaa!



College Slice

:agreed:

Adbot
ADBOT LOVES YOU

Rosalind
Apr 30, 2013

When we hit our lowest point, we are open to the greatest change.

First a few caveats:
  • I am not a Javascript programmer.
  • I am not technically even a programmer at all
  • All the code I write is completely self-taught as I go to solve problems in my workplace so there's probably better ways to do the things I'm doing.
So with those in mind, I work for a research team as their head data person. As part of our research, we collect surveys from participants using Qualtrics. Qualtrics has a neat little feature where you can embed bits of Javascript into a question. We have a study where we need to calculate the difference in days from when they completed their first survey compared to when they are completing their current survey, but the calculation seems to work inconsistently on mobile devices. The code right now looks like this:

code:
Qualtrics.SurveyEngine.addOnload(function()
{
  var surv1date=new Date("${e://Field/day1date}");
      surv1date.setHours(0);
      surv1date.setMinutes(0);
      surv1date.setSeconds(0);
      surv1date.setMilliseconds(0);
  
  var one_day=86400000;
  
  var difference = Math.abs(todayDate.getTime() - surv1date.getTime())/one_day + 1;
  Math.round(difference);
	
var intCount = 1;
var daydiff = null;

	do {	
  //$('daydiff').value = Math.round(difference);
   Qualtrics.SurveyEngine.setEmbeddedData('daydiff', Math.round(difference));
	daydiff = Math.round(difference);
	intCount++;
}
while (intCount <= 10  && (daydiff == undefined || daydiff == null || daydiff == NaN || isNaN(daydiff) == true));
	
	var strday = "on Day ";
	var strfinal = strday.concat(daydiff);
	var newQuestionText = questionText.replace("on Day", strfinal);

	$(this.questionContainer).down('.QuestionText').innerHTML = newQuestionText;

});
;
On mobile devices, it appears sometimes that this code is not running correctly and daydiff is not calculated, but other times it works fine. It will work one day and not the next on the same phone, same browser, same everything. I set it up to loop through the daydiff calculation up to 10 times thinking that might make a difference. We've seen the problem on both iOS and Android devices, but never on a desktop device. Javascript was enabled on these devices. Any ideas?

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply