Page 1 of 2

Browser not visible

Posted: Sun Mar 03, 2013 4:44 pm
by snm
I have browser on card of stack and stack script:

Code: Select all

on openStack
   browserInit
end openStack

on closeStack
   browserClose
end closeStack

on browserInit
   if (the cBrowserID of me) is not empty then
      answer "Browser is already initialized"
      exit to top
   end if
   get revBrowserOpen (the windowId of me, "http://www.studionm.pl")
   if it is not an integer then
      answer "Failed to open browser"
      exit to top
   end if
   set the cBrowserID of me to it
   revBrowserSet it, "rect", (10,50,the width of me -10, the height of me - 10)
   revBrowserSet it, "visible", true
   revBrowserSet it, "showborder", true
end browserInit

on browserClose
   if the cBrowserID of me is empty then
      answer "There is not open browser"
      exit to top
   end if
   revBrowserClose (the cBrowserID of me)
   set the cBrowserID of me to empty
end browserClose

on setHtml
   if the cBrowserID of me is empty then exit to top
   revBrowserSet (the cBrowserID of me), "url", fld "urlField" of me
end setHtml

on resumeStack
   setHtml
end resumeStack
I have also field with url and button triggering "setHtml" handler.

Everything is working as expected until I set "the visible of myStack" to FALSE (when I want to hide it) and back to TRUE when I want to use it again.
My stack is then visible with all objects on it but browser doesn't show any content or even border. It doesn't help any "revBrowserRedraw" or "revBrowserRefresh" command.

Checking by "revBrowserGet" function the browser properties "rect", "visible", "show border", "url" and "htmltext" seems everything is OK. I see there expected content.

When I trigger "setHtml" handler, the content of browser properties "url" and "htmltext" changes as expected, but content and borders of the browser is still not visible.

Did I missed something, or is it the bug? Any help?

Thanks in advance,
Marek

Re: Browser not visible

Posted: Sun Mar 03, 2013 5:38 pm
by Klaus
Hi Marek,

I am not sure if this is related, but do not use IT more than once! IT changes content when you least exspect it :D

Always put it into another variable a soon as possible, if not completely avoid it:

Code: Select all

...
   PUT revBrowserOpen (the windowId of me, "http://www.studionm.pl") into tBrowserID
   if tBrowserID is not an integer then
      answer "Failed to open browser"
      exit to top
   end if
   set the cBrowserID of me to tBrowserID
   revBrowserSet tBrowserID, "rect", (10,50,the width of me -10, the height of me - 10)
   revBrowserSet tBrowserID, "visible", true
   revBrowserSet tBrowserID, "showborder", true
...
Best

Klaus

Re: Browser not visible

Posted: Sun Mar 03, 2013 9:14 pm
by snm
Thanks a lot Klaus for reply.

I changed all "IT" instances to local script variable tBrowserId, but the behaviour is the same. This is my final code:

Code: Select all

local tBrowserId

on openStack
   put empty into tBrowserId
   browserInit
   pass openStack
end openStack

on closeStack
   if tBrowserId is an integer then browserClose
   pass closeStack
end closeStack

on browserInit
   if tBrowserId is an integer then
      answer "Browser is already initialized"
      exit to top
   end if
   put revBrowserOpen (the windowId of me) into tBrowserId
   if tBrowserId is not an integer then
      answer "Failed to open browser"
      exit to top
   end if
   revBrowserSet tBrowserId, "rect", (10,50,the width of me -10, the height of me - 10)
   revBrowserSet tBrowserId, "visible", true
   revBrowserSet tBrowserId, "showborder", true
end browserInit

on browserClose
   if tBrowserID is an integer then
      revBrowserClose (tBrowserId)
      put empty into tBrowserID
   end if
end browserClose

on setHtml
   if tBrowserId is empty then exit to top
   revBrowserSet (tBrowserId), "url", fld "urlField" of me
end setHtml

on resumeStack
   go to card 1 of stack "BrowserTest"
   resetBrowser
   setHtml
   pass resumeStack
end resumeStack

on resizeStack pw, ph
   local tTemp
   revBrowserSet tBrowserId, "rect", (10,50,pw -10,ph - 10)
   put the rect of fld "urlField" into tTemp
   put the width of me -10 into item 3 of tTemp
   set the rect of fld "urlField" to tTemp
   pass resizeStack
end resizeStack

on resetBrowser
   if tBrowserId is an integer then
      browserClose
      browserInit
   end if
end resetBrowser

Even the content is invisible, on message watcher I can see "browserNavigateComplete" and "browserDocumentComplete" messages. Moving the mouse over shows the cursor change to hand over links in invisible content. Very strange!

Marek

Re: Browser not visible

Posted: Sun Mar 03, 2013 9:36 pm
by snm
Additional info:

Triggering "resumeStack" handler from Message Box from time to time shows content of browser, but not always (at ~50%). Why the behavior is not stable?

Marek

Re: Browser not visible

Posted: Sun Mar 03, 2013 10:33 pm
by sturgis
Do you set the stack to invisible at any time? Are you using a backdrop in your application? Are you changing between fullscreen mode and normal mode or changing the decorations of the stack at any time?

Also noticed that every time you "resume" the stack (meaning bring it to the front) you have it reload the page again. Is this intentional?

I'm using your code and it is working for me, but the answer to the preceding questions might help determine the problem.

I also slightly changed how your browser instance is sized so that when the stack is resized the browser will respond accordingly. (separate it out into a new handler then call the resize handler from resizestack)

If you wish I will post the test stack I have here and you can see if it behaves any better. If it does then there is probably some a problem with code elsewhere, or something else going on.


If you can post your stack here (zip it first) that would help greatly too.

Re: Browser not visible

Posted: Sun Mar 03, 2013 11:53 pm
by Simon
Hi Marek,
In Help>Example Stacks there is a browser sample.
Does this work for you?

Simon

Re: Browser not visible

Posted: Mon Mar 04, 2013 8:13 am
by snm
Hi Sturgis and Simon,

Some additional information - I'm working on Mac Os X 10.8.2, LC 5.0.2 - 5.5.4
Maybe the reason is 10.8.2? I can't check it at lower version now until prepare new installation on some spare HDD.

@Sturgis
Do you set the stack to invisible at any time? Are you using a backdrop in your application? Are you changing between fullscreen mode and normal mode or changing the decorations of the stack at any time?
This stack will be in the future working as substack, showing html file or url as needed. So it'll be triggered visible / invisible anytime.
I'm not using any backdrop in my application.
Didn't use fullscreen mode, don't change decorations.
Also noticed that every time you "resume" the stack (meaning bring it to the front) you have it reload the page again. Is this intentional?
It's not needed, but I saw less problems with the visibility of the content if I do this way.
I'm using your code and it is working for me
Please check if really - it can work few times and then few next times (or once) it doesn't.
I also slightly changed how your browser instance is sized so that when the stack is resized the browser will respond accordingly. (separate it out into a new handler then call the resize handler from resizestack)
I'll do it, but I didn't observe any "visibility" problems during resizing.
If you wish I will post the test stack I have here and you can see if it behaves any better.
Yes, please do it. I'll check if it'll be any difference in behaviour.
Please find as attached my zipped stack.

@Simon
In Help>Example Stacks there is a browser sample.
Does this work for you?
The same problem (on page 5 of example). When I make it "visible" loaded html source is visible in a fraction of second and then disappear.

Marek
HtmlMailer Test.zip
(1.89 KiB) Downloaded 206 times

Re: Browser not visible

Posted: Mon Mar 04, 2013 3:51 pm
by sturgis
Have tried your stack, it seems to be working ok for me. I've tried to dump binary files, text files, have thrown lots of stuff at it with no problem (I did remove the resumestack handler again) Have also had it load various web pages, and have had no issues. So my wonder is if there is something going on with the files you are trying to load into the browser.

Can you reliable load web pages? Is it only when you try to load a binfile: or file: that the problem starts?

As for system, i'm on osx 10.8.2 also. Is english your native language?

If the problem starts after trying to view a specific file, can you share the file so that I can try it here?

Re: Browser not visible

Posted: Mon Mar 04, 2013 4:18 pm
by snm
Sturgis, in my opinion the problem is not in HTML file, as this behaviour is common for:
1. any web pages I try
2. any HTML file I try
3. MOST IMPORTANT - if I open this stack, I have buttons for close the browser and the second one to init it without loading any HTML, just set border. When I'm trying to trigger between open and close the browser, and border is visible, then loading HTML works as expected (until you set the visible of stack to FALSE and then to TRUE). But it's often happen that after init (open new instance of browser) the border is not visible - in such situation loading any HTML file doesn't cause it to be visible even if it's loaded).

My first language set in preferences is English, second is Polish.

Please find as attached the file I'm usually test this behaviour.

Marek
html_file_test.zip
(2.36 KiB) Downloaded 203 times

Re: Browser not visible

Posted: Mon Mar 04, 2013 4:45 pm
by sturgis
Haven't been able to make it fail, but there must be something else going on.

During those times when things are acting badly, if you execute

Code: Select all

put revbrowserinstances() 



from the message box, does it only show a single browser instance?

Re: Browser not visible

Posted: Mon Mar 04, 2013 5:21 pm
by snm
Yes, only single instance of browser or empty - depending from the state of browser (opened or closed). As you can see in the stack script it's almost not possible to make 2 instances of browser.

Marek

Re: Browser not visible

Posted: Mon Mar 04, 2013 5:58 pm
by sturgis
At this point i'm stuck, can't seem to reproduce the issue. Works for me whether I have resumestack there or not. *sigh* Silly thought but perhaps a system restart is in order.

Re: Browser not visible

Posted: Mon Mar 04, 2013 6:24 pm
by sturgis
Ok, my guess is this. Either a) there is a trailing or leading space that gets into the URL somewhere, or there is an enter or some other strangeness going on. And once things go strange a close of the browser and reopen does seem necessary. However, if there is still trouble with the URL then resetting wont' really help. Better to validate the URLs ahead of time if possible.

I've made a couple changes to your stack. 1st, catching enterinfield and returninfield so that you can't end up with stray lines in your fields (added to both fields) also have the html load when enter or return occurs in the urlfield.

I've removed the resumestack (commented out.)

Have made a small change to how the text in the url field is handled. I grab word 1 of the text so that it drops any extraneous spaces before or after. It would still be possible to for a user to type in non-valid data, but that could be checked for with "the numer of words..." so that if there is more than 1, do something else. (maybe do a keyword search instead?)

If your filenames/urls/whatever do need to have spaces in them you can probably urlencode things. Still would most likely not need any leading or trailing spaces so you could get word 1 to -1 of field url.. which would take care of that, then urlencode the string (might need to break out binfile: file: and/or http:// and urlencode anything after them.. If they're files may need to escape any spaces etc..)

Here is an adjusted stack you can try. Both fields are empty so you'll have to put your file/url references back in.
https://dl.dropbox.com/u/11957935/BrowserTest.livecode

Hopefully this will fix things for you.

Re: Browser not visible

Posted: Mon Mar 04, 2013 7:30 pm
by snm
Strange, but still not working as expected.

Opening the stack it should run revBrowserOpen - not always visible border after start - in this case 'Set HTML" is loading html (mouse cursor is changing icon between arrow and hand pointer when moving over blank browser, revbrowserinstances() show integer), but you can not see the content. When you click "Reset" button (sometime need to do it more than 1 time to show browser border) and you see the border - then you are - "Set HTML" button and you see the same url correctly.

Above described behaviour shows, that the reason is not in html or it's name. You know after open stack or after "Reset" button if you can see the page from URL field (before you click "Set HTML" button - means before browser will get the html or it's name or url).

Did you check my html file and is it working each time?

I'd like to ask you to make simple test:
- open the stack without setting any url - do you see the border? If not it means you will not see any html content after loading into browser
- if yes, please click a lot of times on "Reset" button (20-50, maybe 100 - I know it's nothing fascinating, but maybe you will see what I am). Do you see the browser border after each each time after each click? If not it means that it's not LC fault and for sure not any fault with html file or it's name.

One more idea - I'll try it tomorrow (it's starting to be late in my country) - maybe the reason is some extension of LC, or even my system installation. But if you can confirm that you got described behaviour, it'll be very significant help for me.

Thanks a lot for your help,
Marek

Re: Browser not visible

Posted: Mon Mar 04, 2013 9:18 pm
by sturgis
Looks like every time I open it on my machine it works fine. If I click the reset repeatedly it occurs as you say quite often. This also means that the "resumestack" that actually closes and reopens the browser instance is adding to the occurrences. Haven't yet found a way around this problem other than not having a reset, and not having. the resumestack handler close and open the instance.

If you need to reset it might work better to have the reset button toggle on and off with a delay between.

To test i grouped all the buttons so that they can be disabled while things are happening.

Then changed handlers around a little.

Code: Select all

on resetBrowser
   set the enabled of group "bControls" to false -- disable to avoid multiple clicks
   if tBrowserId is an integer then
      browserclose -- toggle it closed if it was open
      set the label of button "reset" to "stopped" 
   else
      browserinit -- toggle it open if it was closed
      set the label of button "reset" to "Running"
   end if
   send "resetcontrols" to me in 55 ticks -- reset the controls so they're clickable again using handler below.
end resetBrowser

command resetcontrols
   set the enabled of group "bControls" to true
end resetcontrols
I suspect there are some concurrency issues here and that the external is doing things to go down but is told to come back up before its finished. I'm sure there are better ways around this but i'm having trouble remembering them at the moment. Also be aware there is new and potentially much better browser functionality coming soon so the old revbrowser will probably be superseded. Until then I'd avoid opening and closing it as much as possible, if it will work with your design you can just go invisible to get it out of the way. It should get much much better (I have my fingers crossed) once the changes to livecode start to roll out.