I have followed every instruction as it is in the codelabs tutorial for the FriendlyChat app to the best of my understanding.
I pasted into the index page the code generated from clicking the Add firebase to your web app icon in the console.
However, when I run firebase serve and load the page at localhost:5000, I get an alert telling me I have not configured and imported the Firebase SDK.
How exactly do I configure and import the SDK?
You just have to paste the initialization snippet from:
Firebase Console > Overview > Add Firebase to your web app
in index.html file in web-start folder.
I found the the above answer a bit unclear but managed to solve it with this method in case it helps anyone:
Go to the Firebase main page
Top right (next to your profile image) you'll find 'Go To Console' click on it
There you'll find your 'FriendlyChat' project, click on it
On the left, under the Firebase icon, you'll find a gear icon (settings), go there
Scroll down and you'll find a window with your web apps
There is a title 'SDK setup and configuration '
Make sure you include the 'automatic' code in index.html if you haven't already. It will look similar to this:
<script src="/__/firebase/8.6.3/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="/__/firebase/8.6.3/firebase-analytics.js"></script>
<script src="/__/firebase/init.js"></script>
Make sure you include the 'CDN' code in index.html if you haven't already (remember to put it before any firebase script calls). It will look something like this:
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.6.3/firebase-analytics.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "...",
authDomain: "...",
projectId: "...",
storageBucket: "...",
messagingSenderId: "...",
appId: "...",
measurementId: "..."
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
firebase.analytics();
</script>
Note: if you didn't include analytics I suppose you shouldn't include the analytic scripts (just copy and paste the code given to you on the website)
This stopped the alert from showing up for me.
Related
[I am receiving the all files in console but showing in the frontend and automatically refresh showing the whitescreen][1]
Package.json fileQ5XvT.png
To resolve white/blank screen deployment of react app in Azure, try either of the following ways:
In package.json add "homepage": "."
Make sure to publish from build folder instead of public folder
In your index.html, make sure to check to specify correct JavaScript bundle.
References: How to fix the Blank screen After a Static Deployment with create-react-app and I have deployed a azure-webapp and the page displays blank
You can see this other post: Blank page after running build on create-react-app
If you're using react-router and trying to open index.html directly in the browser (or using electron, which essentially does that), in addition to setting homepage as others have suggested, replace your BrowserRouter with a HashRouter.
Inside a Firebase project called originalawesome I set up a second site on Firebase Hosting, then I have:
originalawesome.web.app
secondawesome.web.app
The first one (originalawesome) has a JS application in production.
In the second (secondawesome) I want to install a Flutter Web App and for this I am following the following steps:
firebase init
(I select Hosting)
(I select to use an existing project)
(I select the project - originalawesome) //secondawesome is not an option
There it asks me to select the directory to publish, so I suppose the Flutter Web application will publish on my site in production, which is wrong.
Reading the documentation in Share project resources across multiple sites , when deployments are to be made in different sites, the Deploy Targets are requested to be differential with the following command:
firebase target: apply hosting secondawesome secondawesome
However, when I run it I get an error because I don't have a firebase json file yet.
Error: Not in a Firebase app directory (could not locate
firebase.json)
The question is, How can I deploy a Flutter Web App on a second Firebase Hosting without deleting the previous one?
After a fair amount of trial and error the solution is as follows:
In the App Root Directory (it's very important):
flutter build web --web-renderer html //In my case, I will
//generate html web rendered. It will create a firebase.json
//file and others
firebase target:apply hosting originalawesome originalawesome
firebase target: apply hosting secondawesome secondawesome
//It will create records in .firebaserc file
In firebase.json file, you need to include:
{
"hosting": {
"target": "secondawesome", //deploy target
//(previously created on Firebase Hosting Console)
"public": "build/web", //build/web is the directory of the Flutter Web App build
///rest of file
Now yes, run...
firebase init
? What do you want to use as your public directory? build/web
? Configure as a single-page app (rewrite all urls to /index.html)?
Yes
? Set up automatic builds and deploys with GitHub? No
? File build/web/index.html already exists. Overwrite? No
To finish and upload the files to the Firebase Hosting ...
firebase deploy --only hosting:secondawesome
I hope it serves someone else!!
I have seen that other similar questions have been asked, and that the error was having the analytics code in the main js file rather than the service-worker.js file. In this case all the code is in the service-worker.js file.
Setup: node 16.0.0 (also does the same with node 15.x.x), and static site built with eleventy
For google analytics I use the analytics.js file. Basically this with a few other options added:
<!-- Google Analytics -->
<script>
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', 'UA-XXXXX-Y', 'auto');
ga('send', 'pageview');
</script>
<script async src='https://www.google-analytics.com/analytics.js'></script>
<!-- End Google Analytics -->
The service-worker.js code in question:
import * as googleAnalytics from 'workbox-google-analytics';
googleAnalytics.initialize({
parameterOverrides: {
cd1: 'offline',
},
});
The service worker in general works absolutely fine. It has various routing routines, precache etc., and the google analytics code seems to do what it should. I can see items caching in IndexedDB when offline, and then the queue clearing when connectivity comes back. I can also see on my google analytics page hits for 'offline' as detailed in the parameterOverrides in the code above.
...so all would seem well, but in the console I still get the following:
service-worker.js?hash=4f292a2050:4259 Uncaught (in promise) TypeError: Cannot use 'in' operator to search for 'sync' in undefined
at Queue._addSyncListener (service-worker.js?hash=4f292a2050:4259)
at new Queue (service-worker.js?hash=4f292a2050:4077)
at new BackgroundSyncPlugin (service-worker.js?hash=4f292a2050:4341)
at initialize (service-worker.js?hash=4f292a2050:4515)
at service-worker.js?hash=4f292a2050:4647
at service-worker.js?hash=4f292a2050:65
I have not run the service worker through terser yet, so it is readable for anyone who wants to have a look.
https://www.thetestspecimen.com/ (then look in dev tools-->application-->service-worker.js)
I should also note that if I use the standard:
googleAnalytics.initialize();
it still does the same thing.
Obviously something is amiss, but I can't figure out what. Any suggestions appreciated
I have seen that other similar questions have been asked, and that the
error was having the analytics code in the main js file rather than
the service-worker.js file. In this case all the code is in the
service-worker.js file.
That is, in fact, what's going on here. The HTML for https://www.thetestspecimen.com/ includes
<script async="" defer="" src="/service-worker.js?hash=4afd6f55e2"></script>
which means that code which is meant to run in the context of the ServiceWorkerGlobalScope (in which self.registration is defined) is instead being run in the window global scope, where self.registration is undefined. That is what's leading to the Cannot use 'in' operator to search for 'sync' in undefined runtime error.
Just adjust your build to ensure that you don't end up with that <script> tag executing your service worker code as part of your main app, and you should be fine.
I am not able to see my SPA page after deploying it to Azure WebApp from VS Code. Its says
"Hey, Node developers!
Your app service is up and running.
Time to take the next step and deploy your code."
I have seen at so may site that I need to set default document and New physical path. But i don't see any Default Document Tab in Configuration menu of Web App. There are only three tabs. 1- Application Setting 2- General Setting 3- Path Mapping.
The Issue is where to set the Default document and new physical path.
If you deployed to a Node Linux Web App the default document would be hostingstart.html located in /home/site/wwwroot/.
According this document:Things You Should Know: Web Apps and Linux, there is a description about default document in a Node.js app.
When you create a Node.js app, by default, it's going to use hostingstart.html as the default document unless you configure it to look for a different file. You can use a JavaScript file to configure your default document. Create a file called index.js in the root folder of your site and add the following content.
So go to your ssh terminal, navigate to /home/site/wwwroot , create the index.js with the following code:
var express = require('express');
var server = express();
var options = {
index: 'index.html'
};
server.use('/', express.static('/home/site/wwwroot', options));
server.listen(process.env.PORT);
I have an existing webapp that I'd like to package up as a chrome packaged app, but I'm getting the following error when trying to hit google analytics:
Refused to load the image
'http://www.google-analytics.com/__utm.gif...' because it violates the
following Content Security Policy directive: "img-src 'self' blob:
filesystem: data: chrome-extension-resource:".
Adding content_security_policy to my manifest.son as described here seems to be out of date and is giving me the error.
There were warnings when trying to install this extension:
'content_security_policy' is only allowed for extensions and legacy
packaged apps, but this is a packaged app.
What is the package app way to register a google analytics page view?
The apps documentation says:
Your Chrome App can only refer to scripts and objects within your app, with the exception of media files (apps can refer to video and audio outside the package). Chrome extensions will let you relax the default Content Security Policy; Chrome Apps won’t.
Use chrome-platform-analytics version of the GA script that supports apps
Include the GA script in your app package, load it as a local script:
<script src="google-analytics-bundle.js"></script>
<script src="mainwindow.js"></script>
Add the necessary permissions in manifest.json:
"permissions": ["https://www.google-analytics.com/*"]
Initialize it:
service = analytics.getService('my_app');
service.getConfig().addCallback(function(config) {
console.log(config.isTrackingPermitted());
config.setTrackingPermitted(true);
});
// Get a Tracker using your Google Analytics app Tracking ID.
tracker = service.getTracker('UA-XXXXX-X');
// Record an "appView" each time the user launches your app or goes to a new
// screen within the app.
tracker.sendAppView('MainView');
The code is quoted from Google analytics app in the official app samples repository on github.