New Mars Forums

Official discussion forum of The Mars Society and MarsNews.com

You are not logged in.

Announcement

Announcement: As a reader of NewMars forum, we have opportunities for you to assist with technical discussions in several initiatives underway. NewMars needs volunteers with appropriate education, skills, talent, motivation and generosity of spirit as a highly valued member. Write to newmarsmember * gmail.com to tell us about your ability's to help contribute to NewMars and become a registered member.

#101 2022-11-01 17:55:46

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re new JavaScript TestID version ...

Here is the same program running on Windows 7...

Run Status

Progress detail is to be reported here
Current ID is: 12345 After Fetch -
Current ID is: 12346 After Fetch -
Report from inside Fetch
Length of result: 7485
Show urlTestID http://newmars.com/forums/userlist.php? … estID12345
Show if TestID found: TestID12345
Show if Member Member
Show location of match 2993
This is from inside Fetch next item is result
Report from inside Fetch
Length of result: 7485
Show urlTestID http://newmars.com/forums/userlist.php? … estID12346
Show if TestID found: TestID12346
Show if Member Member
Show location of match 2993
This is from inside Fetch next item is result
This version ran on Edge on Windows 10

Development environment is Visual Studio Code

(th)

Offline

#102 2022-11-02 06:11:56

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

The initial inspiration for the current JavaScript learning process was the goal of providing you with a way to update the banned TestID's to member status.

That motivation has gone away, because the existing "Simulated Human" software completed the task.

However, momentum to complete the learning effort was built up, and since progress appears to have occurred, I'm leaning toward continuing to finish the current mini-project, to report on status of TestID's from the Users table.

Please start thinking about other needs you may have, that the new software might be enlisted to address.

Today I'm looking to see if I can pull data from the <div> area on the web page.

The problem under investigation is how to collect data from the JavaScript Fetch command.

What I have learned so far is that if I try to collect data inside the Fetch block, all I get is an empty "Promise". On the other hand, clearly the console.log method is able to wait until there is something to work with.

The most recent advance was provided by an Internet contributor, who showed a very simple way to direct the console.log output to the web page where the application is running.

What this implies is that the data can be delivered to the web page from the Fetch, and then accessed by the javaScript outside the Fetch.

My intention for today is to (attempt to) confirm this guess.

What this could lead to is transparency of operation, because the operator would be able to see data collected while it is being assembled on the web page for further processing.

What is more ... there is (apparently) a capability to write data to the local hard drive, so a report of work done could be delivered to a log, much as WBA currently writes progress details to a log.

(th)

Offline

#103 2022-11-02 11:45:29

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

https://www.dropbox.com/s/avsl7uux1sft7 … 3.htm?dl=0

The JavaScript at the link above "works" in the sense that it does not have any runtime errors, and it does pull data from NewMars.

However, my theory that writing data to the web window might solve the Promise/Delivery problem was proven incorrect.

If you run the program, (and study the code) you'll see that the data you see on the screen is delivered ** after ** the call to the fetch.

I suppose one interpretation is that the call to the fetch sets that function off to perform the requested duty, while the calling function (ie, a button) goes on about it's business.

Gaining access to the data after it has been delivered remains elusive.

(th)

Offline

#104 2022-11-02 18:56:30

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

https://www.dropbox.com/s/47rmhxv5a048c … 6.htm?dl=0

The version of the sample program at the link above still does not save data coming out of the Fetch, except as a display on the web form. I've investigated a number of suggested solutions, but nothing I've tried has worked.

I'm saving ** this ** version for you to try (if you have time) because I tweaked the output to make it a bit more readable.

I also reset the whiteBoard between TestIDs, to try to avoid saving too much data, but I'm not sure if the reset had any effect. 

You can see the changes if you run over several ID's (eg, 12345-12348)

In my reading (so far) I'm getting a lot of reinforcement on the concept of "Promises", but only one tiny hint about getting the deliverable.

One Internet contributor said he tried a timer to wait for data to be delivered.

That seems (to me at least) a bit on the crude side, since the whole point of asynchronous programming is to eliminate that kind of brute force.

(th)

Offline

#105 2022-11-02 21:02:03

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re Promises vs Delivery of data in Fetch ....

While searching the Internet for guidance, I found an example that uses a SpaceX web site to demonstrate how to use data from one fetch to feed another.

The little sample code works, or at least it returns results that look reasonable.

I'm not sure this is quite what I'm looking for, but I'll study it in more detail tomorrow.  It actually calls the SpaceX web site three times in all.

I'm a little bit doubtful, because everything happens in side one great big Fetch.

However, it is ** definitely ** showing that data has arrived from the first Fetch.

The key seems to be use of the ".then" structure.

One other thing that is interesting about the sample is that it did not seem to need the Proxy server.  It runs with the Proxy server, but it ran without it.

Here's a link to the demo, if you want to try it...

// https://stackoverflow.com/questions/409 … javascript

Update: I just learned that JavaScript can replace the web page it starts with, as long as the new page comes from the local source.

This might be useful to replace the set up / launch page with a page just for individual TestID's...

The issue I am attempting to address is the long tail that the current design generates.

If you wanted to perform some action for 300 user ID's (for example) the current design would generate a tail that would include details for all 300.

An alternative is to load a replacement page for each TestID.

The mechanism appears to be to write something to the address bar, and to use a "location.reload()" command.

The mechanism to pass data from the setup page to the individual TestID page might be the address bar, or it might be a file on disk.

(th)

Offline

#106 2022-11-03 15:20:08

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript progress...

https://www.dropbox.com/s/noppjqkog9wyg … 1.htm?dl=0

The link above will provide a slightly modified version of the TestID lookup.

This one adds a path for an eventual data file, and shows it on the web page.

The path is currently for Windows, and in any case, it doesn't do anything.

It might make sense to ask the operator to specify operating system, or perhaps there is a way to do that at run time.

I tried setting up output to a file, but Edge balked at my syntax, so that remains for another day.

If you are testing these versions, remember to obtain permission from the demo proxy site.

(th)

Offline

#107 2022-11-03 16:34:09

kbd512
Administrator
Registered: 2015-01-02
Posts: 7,440

Re: Java (r) or Javascript Computer Language

tahanson43206,

How is testing of the new solution going?

Offline

#108 2022-11-03 17:38:50

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For kbd512 re #107

First, thank you (again) for providing a starting seed for this initiative! 

Second, thanks for your inquiry about progress!

For SpaceNut ... please answer the question posed by kbd512, if you have time.

You are the eventual beneficiary of this work, and it is being carried out in an incremental way so that (hopefully) it will be easy for you to follow as each new capability arrives.

(th)

Offline

#109 2022-11-03 17:44:31

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut .... here is output from a test run on Ubuntu 22.04

Run Status

runReport: Progress detail is to be reported here
Length of whiteBoard before fetch 36
Current ID is: 12345 After Fetch of TestID12345
save data here
Length of whiteBoard after fetch 36
The program is ready to go. Path is: c:\newmars\data\
whiteBoard below

Report to console.log from inside Fetch
Length of result: 7589
Show urlTestID http://newmars.com/forums/userlist.php? … estID12345
Show if TestID found: TestID12345
Show if Member Member
Show location of match 2987
End of console.log from inside Fetch
This version ran on Edge on Windows 10

Development environment is Visual Studio Code

(th)

Offline

#110 2022-11-03 19:37:57

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut .... here is a follow up on data storage that might help with the TestID JavaScript ....

https://blog.logrocket.com/localstorage … ete-guide/

This quote is of more text than I was intending, but there is a lot more so if anyone is interested it is available at the blog site.

Nosa Obaseki
Front-end dev currently building amazing products @theflutterwave ???
localStorage in JavaScript: A complete guide
December 29, 2020  3 min read

JavaScript localStorage
Editor’s note: This post was updated on 29 December 2020.

In this tutorial, we’ll show you how to use the localStorage mechanism and Window.localStorage property and review the basics of web storage in JavaScript.

We’ll cover the following in detail:

What is the Web Storage API?
What is the difference between sessionStorage and localStorage?
What is localStorage in JavaScript?
Where is localStorage stored?
What is Window.localStorage?
How does localStorage work?
setItem(): How to store values in localStorage
getItem(): How to get items from localStorage
removeItem(): How to delete localStorage sessions
clear(): How to delete all items in localStorage
key(): How to get the name of a key in localStorage
localStorage browser support
localStorage limitations
What is the Web Storage API?
The Web Storage API is a set of mechanisms that enable browsers to store key-value pairs. It is designed to be much more intuitive than using cookies.

The key-value pairs represent storage objects, which are similar to objects except they remain intact during page loads, and are always strings. You can access these values like an object or using the getItem() method (more on that later).

What is the difference between sessionStorage and localStorage?
The Web Storage API consists of two mechanisms: sessionStorage and localStorage. Both sessionStorage and localStorage maintain a separate storage area for each available origin for the duration of the page session.

The main difference between sessionStorage and localStorage is that sessionStorage only maintains a storage area while the browser is open (including when the page reloads or restores) while localStorage continues to store data after the browser is closed. In other words, whereas data stored in sessionStorage is cleared when the page is closed, data stored in localStorage does not expire.

In this tutorial, we’ll focus on how to use localStorage in JavaScript.

What is localStorage in JavaScript?
localStorage is a property that allows JavaScript sites and apps to save key-value pairs in a web browser with no expiration date. This means the data stored in the browser will persist even after the browser window is closed.

For a visual refresher on how to use localStorage in JavaScript, check out the video tutorial below:


Where is localStorage stored?
In Google Chrome, web storage data is saved in an SQLite file in a subfolder in the user’s profile. The subfolder is located at \AppData\Local\Google\Chrome\User Data\Default\Local Storage on Windows machines and ~/Library/Application Support/Google/Chrome/Default/Local Storage on macOS

Firefox saves storage objects in an SQLite file called webappsstore.sqlite, which is also located in the user’s profile folder.

What is Window.localStorage?
The localStorage mechanism is available via the Window.localStorage property. Window.localStorage is part of the Window interface in JavaScript, which represents a window containing a DOM document.

The Window interface features a wide range of functions, constructors, objects, and namespaces. Window.localStorage is a read-only property that returns a reference to the local storage object used to store data that is only accessible to the origin that created it.

How does localStorage work?
To use localStorage in your web applications, there are five methods to choose from:

setItem(): Add key and value to localStorage
getItem(): This is how you get items from localStorage
removeItem(): Remove an item by key from localStorage
clear(): Clear all localStorage
key(): Passed a number to retrieve the key of a localStorage

This is a feature of JavaScript that might be easier to use than file storage on a hard drive.

In reading about doing file storage on the hard drive, I picked up on concerns about security.

LocalStorage is provided by the browser itself.

(th)

Offline

#111 2022-11-05 08:04:37

SpaceNut
Administrator
From: New Hampshire
Registered: 2004-07-22
Posts: 28,959

Re: Java (r) or Javascript Computer Language

My headache is keeping me from focusing this morning so I will be back to read the last dozen posts or so since last week.

Offline

#112 2022-11-05 10:44:05

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

Breakthrough!

Data from Promise is Resolved and delivered to localStorage!

The experiments to get there were a catalog of things that don't work!

I'll take a break and return to post a link to the breakthrough code.

The "secret" turned out to be placement of the command to write data.

I don't understand why the successful structure worked, but will accept it as a hurdle jumped and move on to the next step.

(th)

Offline

#113 2022-11-05 10:53:03

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut ...

Below is a link to a version of the TestID JavaScript that writes data to localStorage

https://www.dropbox.com/s/j7w5dyhxlqrt3 … 3.htm?dl=0

Remember to run the URL to the proxy demo site to request permission.

Look at localStorage before you run the program.

Clear localStorage with localStorage.clear if it contains debris left by other programs.

Run the program and look in Local Storage.

For this test, I recommend just testing with one ID (such as TestID12345).

I'm not sure what will happen if you run a sequence.

It's quite possible the multiple results will be stored.

Clear localStorage after your experiment.

In the next version, I'll move the data to sessionStorage, so it clears automatically.

Update after testing on several different machines and operating systems ...

The behavior of localStorage appears to differ a bit between browsers ...

Every one I tested accepted the TestID12345 downloaded web page.

However, localStorage.clear seemed to be a bit sticky. 

I'll change to sessionStorage tomorrow, to see if it carries data from one web page to another.

There might be a way to clear localStorage along with History and other classes of saved data in the Tools section.



(th)

Offline

#114 2022-11-05 21:04:58

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

Here is a version of the TestID sample program that writes to sessionStorage.

https://www.dropbox.com/s/3xp5mmlvg1uwk … 1.htm?dl=0

I've confirmed that the sessionStorage feature saves data between reloads of the web page, but deletes the storage when the browser is closed.

I ** think ** the hurdles have been jumped, and the path forward for the JavaScript part of this initiative looks reasonably clear ...

The piece that I'm hoping you can research and solve is how to set up a local proxy server.

Right now, thanks to the generosity of the person/organization who provide the free CORS proxy for development, we are able to continue improving the JavaScript program to perform lookups and eventually updates.

However, at some point, we need to figure out how to create and use our own proxy server.

(th)

Offline

#115 2022-11-06 06:52:48

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re use of localSession...

This morning I tried the new version on a little Chromebook laptop...

Unlike the Windows 10 Edge, which is cluttered with debris from all the vendors who show up on the default web page, the localStorage was clean as a whistle.  More importantly, since this version works with localSession, the Chromebook allowed copy of the data written to localSession, so you can see what you can expect on your system...

Storage {TestID12345: "<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Stric…v class="end-box"></div>↵</div>↵↵</body>↵</html>↵", length: 1}

Overnight I thought about how to arrange for flow between the Setup page and the Worker page.

The data can be passed as shown above.

However, the Worker page also needs parameters to be supplied by the setup page.

At a minimum, these would include:

Current number (ie, 12345 in the example)

Target number (ie, 12345 in the example)

The Worker page would study the passed data and collect any information needed.

In addition, here is where any update would be performed if one is needed.

Finally, the Worker would decide if another worker is needed, or if the Wrapup/Summary page should be loaded.

Loading another page from the local hard drive has not been tested, but I expect it will work as advertised.

The mechanism for delivering data to the hard drive for operator review might be to use the localStorage feature.

However, writing to a log file would be a traditional way of delivering data about a run.

The complication (from what I am gathering from reading) is that for security reasons, the file should be approved by the operator.

That could be done by the Setup page, in which case the name of the file would be passed via sessionStorage as well.

Still, I ** think ** the major hurdles are in the rear view mirror, so progress should now occur as time permits.

Ultimately, the remaining ** big ** hurdle is the local proxy server, which I hope you will have figured out before it is needed.

(th)

Offline

#116 2022-11-06 09:21:32

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re possible use of localSession....

Ubuntu Chromium may be a bit behind the development curve ...

Today I asked it to show the status of the local storage and session storage spaces, and got this:

localStorage
Storage {length: 0}
localSession
VM88:1 Uncaught ReferenceError: localSession is not defined
    at <anonymous>:1:1
(anonymous) @ VM88:1

One of my goals is to be able to run the JavaScript anywhere, so the lack of localSession would be a problem.

I'll try FireFox next ...

Update a few minutes later ... Here's a surprise ...

FireFox knows the words localStorage and localSession because it offers them in a popup list, but it claims the are not recognized.

It just occurred to me that FireFox may have implemented strict security controls, so it may be necessary to give permission to use those keywords.

Update a few minutes later ... Yup! That appears to be the case...

People also ask
Does Firefox support local storage?
How do I enable cookies and local storage in Firefox?
You can access site storage settings in your Firefox Settings as follows:

    In the Menu bar at the top of the screen, click Firefox and select Preferences. Click the menu button. and select Settings.
    Select the Privacy & Security panel and go to the Cookies and Site Data section.

Manage local site storage settings | Firefox Help
https://support.mozilla.org › en-US › storage
Search for: How do I enable cookies and local storage in Firefox?

(th)_

Offline

#117 2022-11-06 11:17:47

kbd512
Administrator
Registered: 2015-01-02
Posts: 7,440

Re: Java (r) or Javascript Computer Language

tahanson43206,

I'm glad you were able to resolve your coding issue. smile

Offline

#118 2022-11-06 11:27:42

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For kbd512 re #117

Thanks for keeping an eye on things!

The key question remains ... will SpaceNut be able to run this software?

He's been battling biology recently, and I hope he's gaining on the bugs.

The starting kernel you provided has evolved a bit since the start, and SpaceNut was able to run earlier versions as they came along, but this initiative depends upon success in New Hampshire.

The related issue (of how to implement a proxy server to facilitate JavaScript fetch requests) is yet unresolved.  I am hoping SpaceNut will find time to solve that challenge. 

In the mean time, I am planning to extend the existing demo so that it operates in three phases: Setup (have now), Worker (to be developed), Summary (to be developed)  This will require successful implementation of an advertised JavaScript capability to reload the web page.

(th)

Offline

#119 2022-11-06 11:56:07

kbd512
Administrator
Registered: 2015-01-02
Posts: 7,440

Re: Java (r) or Javascript Computer Language

tahanson43206,

It's not a "bug", it's a "feature". tongue

Offline

#120 2022-11-06 17:53:07

SpaceNut
Administrator
From: New Hampshire
Registered: 2004-07-22
Posts: 28,959

Re: Java (r) or Javascript Computer Language

Well, that biology was found to be a small Tick on the part of the upper arm on the underside of it as it had not been able to get far into the skin but had been chewing for a period of time since there was a small area where it was found is a bit red from infection. I have treated it with antibiotic ointment after washing it out.

Offline

#121 2022-11-06 18:08:23

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re #120 ... thanks for the good news you caught the agent, but I hope you will enlist medical assistance to make sure the infection was defeated by your natural defenses.  That may well be the case, but it seems to me having professional analysis would be worth whatever the expense might be!

***
I'm pretty sure kbd512 was referring to software "bugs" and not to real ones, such as you encountered.

What were you doing that brought you into contact with this critter!  it's the season for yard work, to be sure.

(th)

Offline

#122 2022-11-07 08:25:59

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

This post is about isolation of code sections from each other.

In the early days of programming, all variables where universal.

As time progressed, the idea of separating variables inside subroutines took hold, and it became possible to pass data back and forth between the main program and subroutines by two pathways .... parameters passed to the subroutine in the call, and values returned by the subroutine to the main program.

An example might be: from calling program: integerResult = function(1,2)

In the example, the integers 1 and 2 are passed to the function, and an integer result is returned to the calling program.

In the case of the JavaScript Browser environment in which the current topic is engaged, there appears to be something similar available.

It appears (and I have not yet confirmed the possibility) that a section of a multiple segmented "program" may be able to 'call' another segment while passing parameters via the localStorage feature of modern browsers.

At the moment, I am imagining a sequence of Setup, Worker and Summary ...

Each of these would be independent html programs stored on the hard drive.

The operator would call Setup, and if the run proceeds as planned, the operator would enter values to be used by Workers.

The Setup html would call the first Worker, and it would pass needed information via localSession

In the present instance, the values passed look like:

1)Starting number
2) Ending number
3) Disk address for writing output
4) The result of a lookup for the first item

The Worker would look for the needed information, and halt if something is missing.

Assuming all is well, the Worker would carry out a task and write to the output file.

The Worker might also initiate an action via the web connection.

The Worker would compare the starting number to the ending number, and call either Worker or Summary

If Summary is called (when it is called) it would look for any information the Worker might have passed.

It would close the output file and report to the operator.

(th)

Offline

#123 2022-11-07 19:25:14

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut ... today was a bye day for the JavaScript initiative.

In preparation for another work session (likely tomorrow) I set up folders for the three html programs: Setup, Worker and Summary.

The input to all three will be the existing version, which appears to work on all OS and browsers tested. 

I'll be interested in seeing your results when you get a chance to try the latest version.  Output of primary interest will be the contents of sessionStorage after a run.  Remember to initialize the Demo Proxy before a test run, unless you are able to set up a local proxy.

(th)

Offline

#124 2022-11-08 13:44:02

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut re JavaScript initiative ...

There may be a way to load a new html file from inside a JavaScript, but as of right now, I haven't found it.

What I ** found ** are a fair number of approaches that don't work.

Update a few minutes later ... as often happens, after giving up, I tried ** one more time ** and things fell into place.

window.location() is a property of the running web page. It is available, if it is invoked as shown.  The result (in this case) was (is) the path to the running file.

https://www.dropbox.com/s/e7er27bw8i61t … 1.htm?dl=0

I hope you are able to squeeze in a bit of time to try these incremental advances, but I realize work, family and other concerns take up most available time.

There is a location.replace() option, so I'm hoping to learn how to use it.

(th)

Offline

#125 2022-11-08 15:33:29

tahanson43206
Moderator
Registered: 2018-04-27
Posts: 17,305

Re: Java (r) or Javascript Computer Language

For SpaceNut ... here is output from a test on Ubuntu ...

Your test on Windows 10 will have a Windows flavor, starting with C:

I found it interesting that the Windows backslashes are NOT shown by the window.location() method.

Run Status

runReport: Progress detail is to be reported here
Current ID is: 12345 After Fetch of TestID12345
save data here

Looking for path
The program is ready to go. Proposed Path is: c:\newmars\data\

window.location file:///media/tahanson/250GbNTSF/NTSFDATA/NewMars/JavaJavaScriptEloquent/Dropbox20221108/20221108SetupHtmlJavascriptCORSVer01.htm

Report to console.log from inside Fetch
Length of result: 7589
Show urlTestID http://newmars.com/forums/userlist.php? … estID12345
Show if TestID found: TestID12345
Show if Member Member
Show location of match 2987
End of console.log from inside Fetch
This version ran on Edge on Windows 10

Development environment is Visual Studio Code

By comparing the Windows and the Linux versions of the path, I am led to the conclusion that the path to the Setup html file can be adapted for loading of the Worker file.  What is not clear at this point is what happens to sessionStorage when a reload is performed.

It is ** supposed ** to persist, but in my first experiment, it did not.

It is possible I performed the reload operation before the NewMars retrieval had completed.

(th)

Offline

Board footer

Powered by FluxBB