B4J Question [ABMaterial] Session variables in safari

PCastagnetti

Member
Licensed User
Longtime User
Last edited:

PCastagnetti

Member
Licensed User
Longtime User
exact

in the link I reported in the first post is indicated

B4X:
srvr.AddFilter("/js/b4j_ws.js", "ABMSessionCreator", False)

It should be replaced with

B4X:
srvr.AddFilter ("/js/b4j_ws.min.js", "ABMSessionCreator", False)

It remains an issue:
the Filter event is executed only if I press the refresh button in the Safari address bar.
This issue is also verifiable with the demo project.



thank you
 
Upvote 0

mindful

Active Member
Licensed User
The filter is executed only when the request is made. If you have b4j_ws.min.js cached then no request for this file will be made so no Filter event will be raised. When you press the refresh button it clears the cache and requests the file again so the Filter event is raised.

I banged my head over this thing lask week also :) With Chrome it needs CTRL+F5 to raise the Filter if that file is cached.
 
Upvote 0

stanmiller

Active Member
Licensed User
Longtime User
exact

in the link I reported in the first post is indicated

B4X:
srvr.AddFilter("/js/b4j_ws.js", "ABMSessionCreator", False)

It should be replaced with

B4X:
srvr.AddFilter ("/js/b4j_ws.min.js", "ABMSessionCreator", False)

It remains an issue:
the Filter event is executed only if I press the refresh button in the Safari address bar.
This issue is also verifiable with the demo project.

thank you

Developing with ABM is full of these type gotchas.

This post from April advises using /js/b4j_ws.min.js
https://www.b4x.com/android/forum/threads/abmaterial-cant-login-in-ipad-or-iphone.65554/#post-415578
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
You can also get the error with the demo project:
edit page_ready of CompActionButtonPage
B4X:
Sub Page_Ready()
    Log("ready!")
   
    ' NEW
    ConnectPage
   
    page.RestoreNavigationBarPosition
    ws.Session.SetAttribute("test","123")
End Sub

edit page_ready of CompAudioPlayerPage
B4X:
Sub Page_Ready()
    Log("ready!")
   
    ' NEW
    ConnectPage   
   
    page.RestoreNavigationBarPosition
    Log(ws.Session.GetAttribute("test"))
End Sub


At this point load AbmActionButton Page to set the session variable, then select the AbmAudioPlayer page.
The log should show a value = null

Now press the refresh button in the Safari address bar (the Filter event is fired)

By repeating the above procedure , the log shows '123'


That at least is what happens with my Ipad

Thank you
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
@mindful
I tried to clear my browser cache and effectively fixes the problem.
Unfortunately when Safari quits, the problem reappears again:(.

the same behavior is obtained by increasing the value of the variable appVersion

thank you very much to all
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
I apologize if I go back on the subject, but I would be sure that the problem is solved.
I tried on a new iPad and everything worked properly (empty cache).
Closing the Safari app and reopening the issue recurred.

I was wondering if the test was done this way

Thank you
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
The sequence that I mentioned is just to highlight the issue (on Windows or Android with Chrome, always work properly).:)
On Safari, only the first time the variable is valued; closing the browser, or the first time that the tablet is turned off, the variable remains = null until I press the refresh button in the Safari address bar .
Thank you
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I tried this scenarios with 2.02:

I added the code you mentioned in post #7 (nothing in the rest of the pages). Additional in Page_NavigationbarClicked in Action = "Contact" I also added
Log(ws.Session.GetAttribute("test")) so I could see the variable test whithout changing pages.

1. Opened ActionButtonPage
2. Opened AudioPage -> 123
3. Opened BadgePage
4. Opened AudioPage -> 123
5. Closed the tab
6. Reopend the Audio page (direct url) -> 123

Pressed the 'home' button on the iPad
Reopened Safari

1. Opened BadgePage (which does nothing to the session variables)
2. Opened AudioPage -> 123

Pressed the 'home' button on the iPad
Reopened Safari

1. I see the AudioPage, pressed the "contact" button -> 123

Turned off the tablet display -> I see in the logs in B4J disconnected
Turned on the tablet display

1. I see the AudioPage, pressed the "contact" button -> 123

Pressed the 'home' button on the iPad
Turned off the tablet display -> I see in the logs in B4J disconnected
Turned on the tablet display
Reopened Safari

1. I see the AudioPage, pressed the "contact" button -> 123

Surfed to google.be (no new tab, same tab new url: left the demo app) I see disconnected in the B4J logs
Pressed the 'home' button on the iPad
Turned off the tablet display
Turned on the tablet display
Reopened Safari (I'm still on the googlel page)

1. went to default demo start page (about) does nothing with the variables.
2. Opened AudioPage -> 123

Surfed to google.be (no new tab, same tab new url: left the demo app) I see disconnected in the B4J logs
Pressed the 'home' button on the iPad
Turned off wifi (no internet connection)
Turned off the tablet display
Turned on the tablet display
Turned on Wifi
Reopened Safari (I'm still on the googlel page)

1. went to default demo start page (about) does nothing with the variables.
2. Opened AudioPage -> 123

If there is a scenario I'm missing, please describe the steps as I did above.

Alain
 
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
Meanwhile, thanks @alwaysbusy for your time

I tried to repeat the procedure described with Ver.2.00 and the result was the same as 2.02 (all right)


But if you replace from your scenario 'Turned off the tablet display' with 'Turn off the tablet', you'll see that the variable remains = null until you press the refresh button in the Safari address bar .

Thank you
 
Upvote 0

alwaysbusy

Expert
Licensed User
Longtime User
I would think this is normal behaviour. I don't have my iPad now but if you do this in Chrome (not Safari!) it works?

1. Open Chrome and open the Demo app
2. Open ActionButtonPage
3. Open AudioPage -> 123

Turn off the tablet (like no power at all?)
Turn on the tablet

1. Open Chrome
2. Still opened AudioPage from before the tablet was turned off -> press "contact" and you would see 123???

That would be incredible from the Chrome browser and the server! But would also mean Safari just does not support this.
 
Last edited:
Upvote 0

PCastagnetti

Member
Licensed User
Longtime User
Ok now I try to install chrome on iPad and then I tell you

Entering this code in ABMApplication of my app appears to have solved the problem (functional but not very clean)

B4X:
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
    Log("Connected")
   
    ws = WebSocket1
    If Not(ws.Session.HasAttribute("Refresh")) Then
        ws.Eval("location.reload(arguments[0])",Array As Object(True))           
        ws.Session.SetAttribute("Refresh",True)
        Log(ws.Session.Id)
        Return
    End If
   
   
........

Thank you
 
Upvote 0
Top