Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

127
Views
Cómo detecta el navegador cuándo el sistema operativo va a hibernar/suspender

Tengo que ejecutar una función antes de que el sistema operativo hiberne/suspenda para cerrar correctamente la conexión webrtc. ¿Hay un detector de eventos o una cierta forma de detectar eso en el navegador?

He intentado con "beforeunload" pero no lo detecta.

almost 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Hay un evento de congelación de borrador

https://wicg.github.io/page-lifecycle/spec.html

pero no está respaldado de manera amplia o confiable al momento de responder

https://caniuse.com/mdn-api_document_freeze_event

Si desea una implementación del evento de congelación, puede encontrarla en https://whatwebcando.today/freeze-resume.html

vuezo a la API

 document.addEventListener('freeze') 

Un evento activado cuando la página ha sido congelada y descargada por el sistema operativo.

 document.addEventListener('resume') 

Un evento activado cuando la página se reanudó después de que el sistema operativo la congelara.

 document.wasDiscarded

Un indicador booleano que indica si la carga actual se ha producido después de que la aplicación web se haya descartado previamente.

Fragmento de código relevante de esa página.

 var target = document.getElementById('target');

if ('wasDiscarded' in document) {
 document.getElementById('wasDiscarded').innerText = document.wasDiscarded.toString();
}

function getState() {
 if (document.visibilityState === 'hidden') {
 return 'hidden';
 }
 if (document.hasFocus()) {
 return 'focused';
 }
 return 'not focused';
};

var state = getState();

function logStateChange(nextState) {
 var prevState = state;
 if (nextState !== prevState) {
 var timeBadge = new Date().toTimeString().split(' ')[0];
 var newLog = document.createElement('p');
 newLog.innerHTML = '' + timeBadge + ' State changed from ' + prevState + ' to ' + nextState + '.';
 target.appendChild(newLog);
 state = nextState;
 }
};

function onPageStateChange() {
 logStateChange(getState())
}

['pageshow', 'focus', 'blur', 'visibilitychange', 'resume'].forEach(function (type) {
 window.addEventListener(type, onPageStateChange, {capture: true});
});

function onFreeze() {
 logStateChange('frozen');
}

window.addEventListener('freeze', onFreeze, {capture: true});

function onPageHide(event) {
 if (event.persisted) {
 // If the event's persisted property is `true` the page is about
 // to enter the page navigation cache, which is also in the frozen state.
 logStateChange('frozen');
 } else {
 // If the event's persisted property is not `true` the page is about to be unloaded.
 logStateChange('terminated');
 }
}

window.addEventListener('pagehide', onPageHide, {capture: true});
 <p>Was current page load initiated from a discarded state? 
 <b id="wasDiscarded">unknown</b>.</p>
 <p>Change the browser tab state to observe the changes log.</p>
<div id="target"></div>
<p><small>Based on the demo from <a href="https://developers.google.com/web/updates/2018/07/page-lifecycle-api" target="_blank" rel="noopener">Google Developers</a>.</small></p>

almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!