Hi,
I am developing a Blazor Wasm application with offline capabilities. When application switch to offline mode, I want to handle the API calls like fetch openid-configuration, application-configuration, and call the identity server etc .currently i am using below service-worker code but am getting 403 error after login. Have you ever encountered this issue, or is there any alternative solution for calling the Api?
self.importScripts('./service-worker-assets.js');
self.addEventListener('install', event => event.waitUntil(onInstall(event)));
self.addEventListener('activate', event => event.waitUntil(onActivate(event)));
self.addEventListener('fetch', event => event.respondWith(onFetch(event)));
const cacheNamePrefix = 'offline-cache-';
const cacheName = `${cacheNamePrefix}${self.assetsManifest.version}`;
const offlineAssetsInclude = [/\.dll$/, /\.pdb$/, /\.wasm/, /\.html/, /\.js$/, /\.json$/, /\.css$/, /\.woff$/, /\.png$/, /\.jpe?g$/, /\.gif$/, /\.ico$/, /\.blat$/, /\.dat$/];
const offlineAssetsExclude = [/^service-worker\.js$/];
async function onInstall(event) {
console.info('Service worker: Install');
self.skipWaiting();
// Fetch and cache all matching items from the assets manifest
const assetsRequests = self.assetsManifest.assets
.filter(asset => offlineAssetsInclude.some(pattern => pattern.test(asset.url)))
.filter(asset => !offlineAssetsExclude.some(pattern => pattern.test(asset.url)))
.map(asset => createRequest(asset));
await caches.open(cacheName).then(cache => cache.addAll(assetsRequests));
}
function createRequest(asset) {
try {
return new Request(asset.url, { integrity: asset.hash, cache: 'no-cache' });
} catch (error) {
console.error(`Error creating request for ${asset.url} with integrity ${asset.hash}:`, error);
return new Request(asset.url, { cache: 'no-cache' });
}
}
async function onActivate(event) {
console.info('Service worker: Activate');
// Delete unused caches
const cacheKeys = await caches.keys();
await Promise.all(cacheKeys
.filter(key => key.startsWith(cacheNamePrefix) && key !== cacheName)
.map(key => caches.delete(key)));
}
async function onFetch(event) {
let cachedResponse = null;
if (event.request.method === 'GET') {
if (event.request.mode === 'navigate' &&
(event.request.url.includes('/connect/') ||
event.request.url.includes('/authentication/') ||
event.request.url.includes('well-known/') ||
event.request.url.includes('/api/abp/'))) {
const cache = await caches.open(cacheName);
cachedResponse = await cache.match(event.request);
if (cachedResponse) {
return cachedResponse;
}
else {
const networkResponse = await fetch(event.request);
if (networkResponse.ok) {
cache.put(event.request, networkResponse.clone());
}
return networkResponse;
}
}
const shouldServeIndexHtml = event.request.mode === 'navigate';
const request = shouldServeIndexHtml ? 'index.html' : event.request;
const cache = await caches.open(cacheName);
cachedResponse = await cache.match(request);
}
return cachedResponse || fetch(event.request).catch(error => console.log(`error on fetch ${error}`));
}
that worked for me, thanks
my problem of favicon icon is only coming on login page, on all other pages it is reflecting the correct icon in tab
ABP Framework version: v8.0.0
UI Type: Blazor WASM
Database System: EF Core (SQL Server,sqlite..) /
Tiered (for MVC) or Auth Server Separated (for Angular): no
Exception message and full stack trace:
SET IMPLICIT_TRANSACTIONS OFF; SET ON; INSERT INTO NOCOUNT[AppInspectionTypes] ([Id], [ConcurrencyStamp], [CreationTime], [CreatorId], [DeleterId], [DeletionTime], [Description], [IsActive], [IsDefault], [LastModificationTime], [LastModifierId], [Name], [TenantId]) OUTPUT INSERTED.[IsDeleted] VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12); 2024-01-08 20:28:39.930 +05:30 [ERR] An exception occurred in the database while saving changes for context type 'APro.Inspector.EntityFrameworkCore.InspectorDbContext'. Microsoft.EntityFrameworkCore.DbUpdateException: Could not save changes because the target table has database triggers. Please configure your table accordingly, see https://aka.ms/efcore-docs-sqlserver-save-changes-and-output-clause for more information. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): The target table 'AppInspectionTypes' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken) ClientConnectionId:43b27918-2f8f-49c7-8873-6b6c08103716 Error Number:334,State:1,Class:16
Steps to reproduce the issue:
When I am trying to use the create entity using my old code that was generated through abp suite 7.2 is giving internal server error after upgrading the code to abp 8
When I am trying to use the create entity using my old code that was generated through abp suite 7.2 is giving internal server error after upgrading the code to abp 8 below is the error SET IMPLICIT_TRANSACTIONS OFF; SET ON; INSERT INTO NOCOUNT[AppInspectionTypes] ([Id], [ConcurrencyStamp], [CreationTime], [CreatorId], [DeleterId], [DeletionTime], [Description], [IsActive], [IsDefault], [LastModificationTime], [LastModifierId], [Name], [TenantId]) OUTPUT INSERTED.[IsDeleted] VALUES (@p0, @p1, @p2, @p3, @p4, @p5, @p6, @p7, @p8, @p9, @p10, @p11, @p12); 2024-01-08 20:28:39.930 +05:30 [ERR] An exception occurred in the database while saving changes for context type 'APro.Inspector.EntityFrameworkCore.InspectorDbContext'. Microsoft.EntityFrameworkCore.DbUpdateException: Could not save changes because the target table has database triggers. Please configure your table accordingly, see https://aka.ms/efcore-docs-sqlserver-save-changes-and-output-clause for more information. ---> Microsoft.Data.SqlClient.SqlException (0x80131904): The target table 'AppInspectionTypes' of the DML statement cannot have any enabled triggers if the statement contains an OUTPUT clause without INTO clause. at System.Threading.Tasks.ContinuationResultTaskFromResultTask`2.InnerInvoke() at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) --- End of stack trace from previous location --- at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state) at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread) --- End of stack trace from previous location --- at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken) at Microsoft.EntityFrameworkCore.Update.ReaderModificationCommandBatch.ExecuteAsync(IRelationalConnection connection, CancellationToken cancellationToken) ClientConnectionId:43b27918-2f8f-49c7-8873-6b6c08103716 Error Number:334,State:1,Class:16
Can you please help me out , that what I am missing