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

189
Views
How to receive online/offline events in Javascript that's executed inside WKWebView on iOS?

I have an iOS app that uses WKWebView to load in local HTML/JS file that contains online/offline event listeners but they aren't fired when user loses/regains connection. Same HTML/JS works on Android.

offline event - https://developer.mozilla.org/en-US/docs/Web/API/Window/offline_event online event - https://developer.mozilla.org/en-US/docs/Web/API/Window/online_event

Is there something specific I need to configure for it to trigger those events?

window.addEventListener('online', () => {
    console.log('Regained internet connection');
});

window.addEventListener('offline', () => {
    console.log('Lost internet connection');
});
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Found what solved it for me. I had to wait for the page to load in before attaching the event listeners like below instead of adding them as soon as script executes.

window.addEventListener('load', async () => {

    window.addEventListener('online', () => {
        console.log('Regained internet connection');
    });

    window.addEventListener('offline', () => {
        console.log('Lost internet connection');
    });

)};
about 4 years ago · Juan Pablo Isaza 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!