Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to save fullscreen state in Firefox?

Following Mozilla's API document on Fullscreen, I've placed the following code in my website, it simply takes the whole document (html element) and makes the page go fullscreen once the user clicks anywhere in the page, and once there's another click, page goes back to normal.

var videoElement = document.getElementsByTagName('html')[0];

function toggleFullScreen() {
    if (!document.mozFullScreen) {
        if (videoElement.mozRequestFullScreen) {
            videoElement.mozRequestFullScreen();
        }
    } else {
        if (document.mozCancelFullScreen) {
            document.mozCancelFullScreen();
        } 
    }
}

window.addEventListener("click", function(e) {
    toggleFullScreen();
}, false);

My question is how can I save this fullscreen state so every time that Firefox loads up, that page is still on fullscreen. Or any workaround? This is for Firefox for Android.

like image 749
ramonovski Avatar asked Apr 11 '18 16:04

ramonovski


People also ask

How do I make Firefox full screen permanently?

Keyboard Shortcuts Toggle Full Screen keyboard shortcut: Press the F11 key. Note: On computers with a compact keyboard (such as netbooks and laptops), press the fn + F11 keys.

How do I get Firefox to always open maximized?

Right-click the Firefox desktop icon and select '''Properties''' then '''Shortcut tab '''then in '''Run '''session scroll and select '''Maximized'''. thank you Please mark "Solved" the answer that really solve the problem, to help others with a similar problem.

How do I stop Firefox from fading in full screen?

You can open the about:config page via the location/address bar. You can accept the warning and click "I accept the risk!" to continue. You can modify these prefs on the about:config page to disable the full screen fade in and fade out. Leave out the quotes around the value (enter two zeros separated by a space).


2 Answers

It's an extreme workaround, but you can make your website a progressive web app and put "display": "fullscreen" in its manifest. Then you can launch your site from the home screen and use it like a fullscreen native app.

like image 142
AuxTaco Avatar answered Oct 13 '22 10:10

AuxTaco


Following my experiments and the specs, this isn't doable, from client browser javascript

This api need an user interaction. We can't activate the fullscreen by scripting.

From the fullscreen api specification:

Fullscreen is supported if there is no previously-established user preference, security risk, or platform limitation.

An algorithm is allowed to request fullscreen if one of the following is true:

The algorithm is triggered by user activation.

The algorithm is triggered by a user generated orientation change.

https://fullscreen.spec.whatwg.org/#model

About activation events:

An algorithm is triggered by user activation if any of the following conditions is true:

The task in which the algorithm is running is currently processing an activation behavior whose click event's isTrusted attribute is true.

The task in which the algorithm is running is currently running the event listener for an event whose isTrusted attribute is true and whose type is one of:

change

click

dblclick

mouseup

pointerup

reset

submit

touchend

https://html.spec.whatwg.org/multipage/interaction.html#triggered-by-user-activation

We can't trigger fullscreens from scripts, or if so, the script must be triggered by the user.

Including simulating a click won't works, this is regular behavior, made to protect user experience.

With some reflexion, we can't agree more on this, imagine any ads page can launch full screens, the web would be a hell to browse!

You told in comment: «I am the only user here»

What you can do if using unix: (( probably alternatives exists in other os )).

Using midori (a lightweight webkit browser), this will start a real fullscreen.

midori -e Fullscreen -a myurl.html

There is no ways to start firefox or chromium in a fullscreen state from the command line, to my knowledge.

But what is doable is to trigger a F11 click at system level, focusing on the good window, just after the page launch. ((sendkey in android adb shell?))

xdotool can do that.

Here is a pipe command line that will launch firefox with myurl.html, search for the most recent firefox window id, then trigger the F11 key on this window.. (Press F11 again to exit)

firefox myurl.html && xdotool search --name firefox | tail -1 | xdotool key F11

This should be easy to adapt for other browsers.

As last alternative, have a look at electron or nw.js.

like image 44
NVRM Avatar answered Oct 13 '22 09:10

NVRM