I try to develop a simple Google Chrome extension using angular CLI but it's stuck on Loading
.
If I try to run my app normally using npm start
and open it in browser's window, it works fine.
I also try to compile my app using ng build
, put my manifest.json
inside my dist
folder but the result is the same.
my manifest.json :
{
"manifest_version": 2,
"name": "Weather for Chrome",
"description": "Weather for Chrome is a simple Google chrome plugin using angular CLI",
"version": "1.0",
"browser_action": {
"default_icon": "assets/Soleil.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
]
}
app.module.ts
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { WeatherService } from "./_services/weather.service";
import { PopupComponent } from "./popup/popup.component";
@NgModule({
declarations: [
AppComponent,
PopupComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
AppRoutingModule
],
providers: [
WeatherService
],
bootstrap: [AppComponent]
})
export class AppModule { }
app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.sass']
})
export class AppComponent {
title = 'app works!';
}
app-routing.module.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.sass']
})
export class AppComponent {
title = 'app works!';
}
I don't know how to debug a chrome extension. Thanks for answers.
Install Chrome extension Then turn on Developer mode -> Load unpacked in order to import your newly compiled app. Remember to import the whole folder, not just the files. You now have everything ready in order to develop your awesome chrome extension with Nx & Angular.
# Background scriptNavigate to the chrome extensions management page at chrome://extensions and ensure developer mode is on. Click the Load Unpacked button and select the broken extension directory.
Right-click anywhere on the web page and select Inspect to open the Developer tools.
I was able to get this working for the basic angular 2 app generate by @angular/cli. The issue I was having was due to an permission error, i.e. Refused to evaluate a string as JavaScript because 'unsafe-eval'
.
I found this error by right clicking the extension icon and selecting Inspect Popup
. I then dug up this post with information regarding evaluation permissions in chrome extensions: Content Security Policy in Chrome App
The solution here works for me. My manifest.json
is in my /dist
folder and I loaded the unpacked extension from this directory. Here is my manifest:
{
"manifest_version": 2,
"name": "Extension",
"description": "This extension ...",
"version": "1.0",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab",
"https://ajax.googleapis.com/"
],
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'"
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With