The PWA application is experiencing issues when offline due to the malfunction of Ionic 4 and the toaster feature with Network Capac

Update: After updating to the latest version of Ionic 4.6.2, I encountered the following exception while in offline mode.

Network status changed {connected: false, connectionType: "none"}connected: falseconnectionType: "none"__proto__: Object
bootstrap:145 GET http://localhost:8100/85.js net::ERR_INTERNET_DISCONNECTED
requireEnsure @ bootstrap:145
webpackAsyncContext @ .*\.entry\.js$ include: \.entry\.js$ exclude: \.system\.entry\.js$ namespace object:407
loadModule @ chunk-09ec7fc0.js:61
(anonymous) @ chunk-09ec7fc0.js:1468
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
initializeComponent @ chunk-09ec7fc0.js:1450
(anonymous) @ chunk-09ec7fc0.js:1604
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke @ zone.js:391
push../node_modules/zone.js/dist/zone.js.Zone.run @ zone.js:150
(anonymous) @ zone.js:889
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
drainMicroTaskQueue @ zone.js:601
Promise.then (async)
scheduleMicroTask @ zone.js:584
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:413
onScheduleTask @ zone.js:301
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.scheduleTask @ zone.js:404
push../node_modules/zone.js/dist/zone.js.Zone.scheduleTask @ zone.js:238
push../node_modules/zone.js/dist/zone.js.Zone.scheduleMicroTask @ zone.js:258
scheduleResolveOrReject @ zone.js:879
resolvePromise @ zone.js:825
(anonymous) @ zone.js:741
Promise.then (async)
(anonymous) @ zone.js:1092
ZoneAwarePromise @ zone.js:910
Ctor.then @ zone.js:1091
createOverlay @ chunk-d83bfeae.js:30
create @ chunk-d83bfeae.js:8
push../node_modules/@ionic/angular/dist/fesm5.js.OverlayBaseController.create @ fesm5.js:4874
(anonymous) @ show-toast.service.ts:13
step @ tslib.es6.js:99
(anonymous) @ tslib.es6.js:80
(anonymous) @ tslib.es6.js:73
ZoneAwarePromise @ zone.js:910
__awaiter @ tslib.es6.js:69
push../src/app/services/utilities/show-toast.service.ts.ShowToastService.showNetworkStateErrorToast @ show-toast.service.ts:12
(anonymous) @ network-state-service.ts:40
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:423
onInvokeTask @ core.js:17290
push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask @ zone.js:422
push../node_modules/zone.js/dist/zone.js.Zone.runTask @ zone.js:195
push../node_modules/zone.js/dist/zone.js.ZoneTask.invokeTask @ zone.js:498
invokeTask @ zone.js:1744
globalZoneAwareCallback @ zone.js:1770
zone.js:682 Unhandled Promise rejection: Cannot read property 'isProxied' of undefined ; Zone...
         

To utilize Network capacitor with Ionic 4, I have ensured proper execution when debugging. However, the toast function is not functioning as expected.

I attempted a solution without success.

Note: The Network Capacitor functionality works correctly but does not display the toast. Testing was conducted both on a browser and Firebase hosting with https.

service.ts

 async WatchConnection() {
    this.networkListener = Network.addListener('networkStatusChange', (status) => {
      this.networkStatus = status;
      if (!this.networkStatus.connected) {
        this.showToastService.showNetworkStateErrorToast('Your internet seems to be down! Please check your network settings!');
      } else {
        setTimeout(() => {
          this.showToastService.toast.dismiss();
          if (this.networkStatus.connected) {
            this.showToastService.showNetworkStateSuccessToast('Internet connection available!');
          }
        }, 3000);
      }
    });

    this.networkStatus = await Network.getStatus();
  }

app.component.ts

 async initializeApp() {
    this.networkStateService.WatchConnection();
  }

Answer №1

I have discovered a workaround while waiting for the Ionic team to resolve this problem.

Here is the solution I found within the toast service:

 constructor(private toastCtrl: ToastController, ) {
    this.toastCtrl.create({ animated: false }).then(t => { t.present(); t.dismiss(); });
  }

Answer №2

For anyone struggling with a similar issue, I encountered the same problem while using Angular Serviceworker. After switching to Workbox (https://developers.google.com/web/tools/workbox), I was able to resolve the issue. Fortunately, since I was developing the app from scratch and had not yet gone into production, the transition to Workbox was seamless.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The unspoken rules of exporting and importing in TypeScript

In comparison to Java (as well as other programming languages), TypeScript provides multiple options for exporting and importing entities such as classes, functions, etc. For instance, you have the ability to export numerous classes, constants, functions ...

The object literal can only define existing properties, and the property 'allAwsRegions' is not found in the 'IResolvable' type

Currently, I am working with the AWS-CDK and attempting to set up a Config Aggregator to combine the storage of configuration logs from all regions. Instead of using an account as the source, I have opted for a region due to restrictions on configuring org ...

Having trouble with removing a language from the router in Next.js when using ni18n?

I've been working on a website using ni18n with Next.js, but I'm having trouble removing the language part from the URL even after trying to force remove it. What I'm aiming for is a URL like this: "http://localhost:3000" Howeve ...

What is the process for integrating a Google Analytics chart from Google Analytics into an Angular 4 application?

I am seeking guidance on how to integrate a Google Analytics chart into my website using Angular 4. Any assistance on the process would be greatly appreciated. ...

Discovering an element in an Array using Angular 2 and TypeScript

In my setup, I have a Component and a Service: Component: export class WebUserProfileViewComponent { persons: Person []; personId: number; constructor( params: RouteParams, private personService: PersonService) { ...

What is the best approach to utilizing directives across multiple modules within Angular?

Recently, I created a directive called uppercase-input.directive.ts I attempted to import and use this directive in multiple components, but encountered the following error I have only shared one file here (organization.module.ts), but there are several ot ...

Having trouble with retrieving data from the service as expected

To facilitate the transfer of data between components, I implemented a service: import { Injectable } from '@angular/core'; import { BehaviorSubject } from 'rxjs/BehaviorSubject'; @Injectable() export class DataTransferService { pr ...

The search functionality in the unit test could not be executed as it is

Encountering an error this.sourceAccounts.find is not a function while running unit test on an array. component.ts: sourceAccounts: Array<IObject>; nameChangedSubscription: Subscription; constructor(private accountService: AccountService) { } ngOn ...

Incorporating a counter feature into an Angular HTML document

In this section, I am displaying the restaurants that are filtered based on their name and address. If no name or address is provided, all restaurants are shown. However, I am facing an issue as I need to incorporate a counter to keep track of the remainin ...

Adjusting canvas height in Storybook - Component does not fit properly due to low canvas height

I had a component that I needed to add to Storybook. It was working fine, but the styling was slightly off. I managed to resolve this by adding inline styling with position: absolute. Here is how it looks now: const Template: any = (args: any): any => ( ...

The issue with the dark/light theming in an input arises when the autocomplete attribute is set to "on"

Seeking advice on applying a light/dark theme to an input field. I have created the input tag in Angular and styled it using Bootstrap for my application. HTML <form [formGroup]="exportDialogueForm"> <div class="form-floating mb- ...

Enhancing Angular 5 with CustomEvent Polyfill for JavaScript

After implementing the code snippet in main.ts file, I encountered an issue with CustomEvent not being added to the window object correctly. Strangely, when I manually add CustomEvent using the JavaScript console, it works fine. This problem arises specifi ...

A guide on dynamically rendering SVGs with ngFor in Angular 4

I need some assistance with dynamically rendering an SVG image in Angular 4 using a coordinate list. I am encountering the following error, and would appreciate any help in resolving it. HTML <svg height="100%" width="100%" (click)="addTag($event)" *n ...

Why am I encountering an HTTP 400 Error when trying to consume the API with a GET request? What could be

I am currently working with a Symfony server that has JWT authentication and an Angular client app that is sending requests. I have successfully implemented a login feature and now I need to retrieve some data to populate a select dropdown. The data I nee ...

Error: Unable to execute this.threadData.pipe function - Unit Testing Angular 6 with JASMIN KARMA

Currently, I am in the process of writing unit test cases for an Angular 6 component. Despite achieving a code coverage of 65%, I have encountered an error within the following code snippet that has been quite bothersome to me. Specifically, I am unsure of ...

The type 'typeof globalThis' does not have an index signature, therefore the element is implicitly of type 'any'. Error code: ts(7017) in TypeScript

I'm encountering an issue with my input handleChange function. Specifically, I am receiving the following error message: Element implicitly has an 'any' type because type 'typeof globalThis' has no index signature.ts(7017) when att ...

Compiling a list of products, but the user interface needs some adjustments

Currently, I have designed a product list menu that includes a hover dropdown feature. This means that when a user hovers over a specific menu item, the corresponding list will automatically appear. However, I am facing two issues with this setup. Firstly, ...

The method this.object.remove does not exist

I'm encountering a situation that closely resembles this Runtime Error this.object.remove is not a function. Despite following the suggested solution, I'm still facing issues. The specific error message I'm getting is this.menuData.remove i ...

Experiencing issues during the execution of "ng serve"

The angular project is named "PaymentApp". When running "ng serve", numerous errors are displayed instead of the default angular template. The message "Cannot GET /" is being shown. Attached images for reference: https://i.stack.imgur.com/faysG.png http ...

searchByTextContentUnderListItemAnchorTag

I would like to utilize the getByRole function for writing my test. However, I am encountering issues when using linkitem or 'link' as the role. It seems that I cannot find the desired element. // encountered error TestingLibraryElementError: The ...