Related
I have installed the template from Electron-vue and I'm experiencing an issue with specific websites. These websites work on Chrome and Edge, yet, fail to completely load in webview.
The following example is the whole setup of the view. The console of this show that Local Storage, Session Storage and IndexedDB only have an entry for the website faselhd but have no data inside. The Cookies has an entry for the website with this type of data fcuid
<webview id="webview_custom" :src="https://www.faselhd.co/" style="height: 100%"></webview>
As far as I understand, there is an issue saving the session of the website and it's working correctly on the normal browsers but cannot save the session in the webview.
I have tried using this policy in my index.ejs, but had no luck.
<meta http-equiv="Content-Security-Policy" content="script-src * 'unsafe-inline' 'unsafe-eval'">
Expected: The website loads and shows the content.
Currently: The website keeps refreshing because the session cannot be saved.
package.json
{
"name": "my-app",
"version": "1.0.0",
"author": "author",
"description": "description",
"license": null,
"main": "./dist/electron/main.js",
"scripts": {
"build": "node .electron-vue/build.js && electron-builder",
"build:dir": "node .electron-vue/build.js && electron-builder --dir",
"build:clean": "cross-env BUILD_TARGET=clean node .electron-vue/build.js",
"build:web": "cross-env BUILD_TARGET=web node .electron-vue/build.js",
"dev": "node .electron-vue/dev-runner.js",
"pack": "npm run pack:main && npm run pack:renderer",
"pack:main": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.main.config.js",
"pack:renderer": "cross-env NODE_ENV=production webpack --progress --colors --config .electron-vue/webpack.renderer.config.js",
"postinstall": ""
},
"build": {
"productName": "app-electron",
"appId": "com.username.app_electron",
"directories": {
"output": "build"
},
"files": [
"dist/electron/**/*"
],
"dmg": {
"contents": [
{
"x": 410,
"y": 150,
"type": "link",
"path": "/Applications"
},
{
"x": 130,
"y": 150,
"type": "file"
}
]
},
"mac": {
"icon": "build/icons/icon.icns"
},
"win": {
"icon": "build/icons/icon.ico"
},
"linux": {
"icon": "build/icons"
}
},
"dependencies": {
"axios": "^0.18.0",
"electron-context-menu": "^0.16.0",
"vue": "^2.5.16",
"vue-electron": "^1.0.6",
"vue-router": "^3.0.1",
"vue-tabs-chrome": "^0.5.1",
"vuetify": "^2.2.17",
"vuetify-loader": "^1.4.3",
"vuex": "^3.0.1",
"vuex-electron": "^1.0.0"
},
"devDependencies": {
"ajv": "^6.5.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-minify-webpack-plugin": "^0.3.1",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.7.0",
"babel-preset-stage-0": "^6.24.1",
"babel-register": "^6.26.0",
"cfonts": "^2.1.2",
"chalk": "^2.4.1",
"copy-webpack-plugin": "^5.1.1",
"cross-env": "^5.1.6",
"css-loader": "^0.28.11",
"deepmerge": "^4.2.2",
"del": "^3.0.0",
"devtron": "^1.4.0",
"electron": "^2.0.4",
"electron-builder": "^20.19.2",
"electron-debug": "^1.5.0",
"electron-devtools-installer": "^2.2.4",
"fibers": "^4.0.2",
"file-loader": "^1.1.11",
"html-webpack-plugin": "^3.2.0",
"jquery": "^3.4.1",
"lodash": "^4.17.15",
"mini-css-extract-plugin": "0.4.0",
"multispinner": "^0.2.1",
"node-loader": "^0.6.0",
"node-sass": "^4.9.2",
"sass": "^1.26.3",
"sass-loader": "^7.3.1",
"style-loader": "^0.21.0",
"url-loader": "^1.0.1",
"vue-html-loader": "^1.2.4",
"vue-loader": "^15.2.4",
"vue-style-loader": "^4.1.0",
"vue-template-compiler": "^2.5.16",
"webpack": "^4.15.1",
"webpack-cli": "^3.0.8",
"webpack-dev-server": "^3.1.4",
"webpack-hot-middleware": "^2.22.2",
"webpack-merge": "^4.1.3"
}
}
You're using the default template electron-vue which it uses a very old Electron 2.0.1 and that is Chrome 61, Node 8.9.3, V8 6.1.534.41 which is quite outdated to properly support Local Storage and Session Storage. You need to update Electron to a newer version.
To your existing project
Update electron to 8.1.x by running yarn add electron (this will update electron to latest 8.1.1)
Open .electron-vue/webpack.renderer.config.js and at line 115 change HtmlWebpackPlugin configuration object to this:
new HtmlWebpackPlugin({
filename: 'index.html',
template: path.resolve(__dirname, '../src/index.ejs'),
templateParameters(compilation, assets, options) {
return {
compilation: compilation,
webpack: compilation.getStats().toJson(),
webpackConfig: compilation.options,
htmlWebpackPlugin: {
files: assets,
options: options
},
process,
};
},
minify: {
collapseWhitespace: true,
removeAttributeQuotes: true,
removeComments: true
},
nodeModules: false
}),
Open src/main/index.js and update/add BrowserWindow webPreferences options like this:
mainWindow = new BrowserWindow({
height: 563,
useContentSize: true,
width: 1000,
// Add these webPreferences options
webPreferences: {
nodeIntegration: true,
webviewTag: true
}
})
Add a webview to your renderer. I had to set <webview src="..."> insted of binding <webview :src="..."> like this:
<template>
<div id="app">
<!-- <router-view></router-view> -->
<webview id="webview_custom" src="https://www.faselhd.co/" style="height: 100%"></webview>
</div>
</template>
<script>
export default {
name: 'vue-electron-webview2'
}
</script>
<style>
/* CSS */
html, body, #app { height: 100% }
</style>
Now run the app using yarn dev and you'll be able to see the the web page properly.
I keep getting this error:
error in ./node_modules/keytar/build/Release/keytar.node
Module parse failed: Unexpected character '�' (1:2)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
(Source code omitted for this binary file)
# ./node_modules/keytar/lib/keytar.js 1:13-52
# ./src/background.js
# multi ./src/background.js
I have background.js set as the main electron file in package.json because I'm using vue/vuetify with it which uses a main.js file as well.
{
"name": "project",
"version": "0.1.0",
"private": true,
"scripts": {
"serve": "vue-cli-service serve",
"build": "vue-cli-service build",
"lint": "vue-cli-service lint",
"electron:build": "vue-cli-service electron:build",
"electron:serve": "vue-cli-service electron:serve",
"postinstall": "electron-builder install-app-deps",
"postuninstall": "electron-builder install-app-deps"
},
"main": "background.js", // <------------------ see right here
"dependencies": {
"axios": "^0.19.0",
"core-js": "^3.4.3",
"jwt-decode": "^2.2.0",
"keytar": "^5.0.0",
"request": "^2.88.0",
"vue": "^2.6.10",
"vue-router": "^3.1.3",
"vuetify": "^2.1.0",
"vuex": "^3.1.2"
},
"devDependencies": {
"#vue/cli-plugin-babel": "^4.1.0",
"#vue/cli-plugin-eslint": "^4.1.0",
"#vue/cli-service": "^4.1.0",
"babel-eslint": "^10.0.3",
"electron": "^7.1.3",
"eslint": "^5.16.0",
"eslint-plugin-vue": "^5.0.0",
"node-loader": "^0.6.0",
"sass": "^1.19.0",
"sass-loader": "^8.0.0",
"vue-cli-plugin-electron-builder": "^1.4.3",
"vue-cli-plugin-vuetify": "^2.0.2",
"vue-template-compiler": "^2.6.10",
"vuetify-loader": "^1.3.0"
},
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
"browserslist": [
"> 1%",
"last 2 versions"
]
}
Searching, it seems this happens when keytar is used in a renderer process. But background.js isn't a renderer process. Or am I missing something? I am completely new to electron.
I needed to mark keytar as external (as mentioned at https://nklayman.github.io/vue-cli-plugin-electron-builder/guide/guide.html#native-modules)
// vue.config.js
module.exports = {
pluginOptions: {
electronBuilder: {
// List native deps here if they don't work
externals: ['keytar']
}
}
}
Once I did that it worked properly.
Run appropriate loader (source).
yarn add node-loader -D
// vue.config.js
configureWebpack: {
devtool: 'source-map',
module: {
rules: [
{ test: /\.node$/, loader: 'node-loader' }
]
}
}
client folder where the react code sitsI am Using react with ruby on rails, I have created a separate folder named client for react code on the root. but whenever I changed something in the react i have to go to the page and refresh it manually, is there any way where I can automatically refresh the page whenever I can make any change in the code?
If you are using create-react-app then it should be available through that package. If you are building your own environment with Webpack, you can use Hot Module Replacement. https://webpack.js.org/guides/hot-module-replacement/
Edit:
Here are some example files from a project I made containing relevant code.
Webpack
const webpack = require('webpack');
const { resolve } = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin');
module.exports = {
entry: [
'react-hot-loader/patch',
'webpack-dev-server/client?http://localhost:8080',
'webpack/hot/only-dev-server',
resolve(__dirname, "src") + "/index.jsx"
],
output: {
filename: 'app.bundle.js',
path: resolve(__dirname, 'build'),
publicPath: '/'
},
resolve: {
extensions: ['.js', '.jsx']
},
devtool: '#source-map',
devServer: {
hot: true,
contentBase: resolve(__dirname, 'build'),
publicPath: '/'
},
module: {
rules: [
{
test: /\.jsx?$/,
enforce: "pre",
loader: "eslint-loader",
exclude: /node_modules/,
options: {
emitWarning: true,
configFile: "./.eslintrc.json"
}
},
{
test: /\.(png|gif|jp(e*)g|svg)$/,
use: {
loader: 'url-loader',
options: {
limit: 8000,
name: 'images/[hash]-[name].[ext]'
}
}
},
{
test: /\.jsx?$/,
loader: "babel-loader",
exclude: /node_modules/,
options: {
presets: [
["es2015", {"modules": false}],
"react"
],
plugins: [
"react-hot-loader/babel",
"styled-jsx/babel"
]
}
},
],
},
plugins: [
new webpack.HotModuleReplacementPlugin(),
new webpack.NamedModulesPlugin(),
new HtmlWebpackPlugin({
template:'template.ejs',
appMountId: 'react-app-root',
title: 'Project Name',
filename: resolve(__dirname, "build", "index.html"),
}),
]
};
Mainly, the entry, devServer, module.plugins and plugins at the bottom have the hot reloading code.
package.json
{
"name": "project",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "webpack-dev-server",
"lint": "eslint src/index.jsx src/**/*.jsx; exit 0",
"lint-fix": "eslint src/index.jsx src/**/*.jsx --fix; exit 0"
},
"repository": {
"type": "git",
"url": "url"
},
"author": "",
"license": "ISC",
"bugs": {
"url": "url"
},
"homepage": "relevant-url",
"dependencies": {
"eslint": "^5.0.1",
"eslint-plugin-react": "^7.10.0",
"file-loader": "^1.1.6",
"npm": "^6.1.0",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
"react-router-dom": "^4.0.0",
"styled-jsx": "^2.2.7",
"url-loader": "^0.6.2"
},
"devDependencies": {
"babel-core": "^6.24.1",
"babel-loader": "^7.0.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"eslint-loader": "^2.0.0",
"html-webpack-plugin": "^2.29.0",
"react-hot-loader": "^3.0.0-beta.7",
"webpack": "^3.4.0",
"webpack-dev-server": "^2.5.0"
}
}
The hot reloading packages in the devDependencies
index.jsx
import React from 'react';
import ReactDOM from 'react-dom';
import App from './components/App';
import { AppContainer } from 'react-hot-loader';
import { HashRouter } from 'react-router-dom';
const render = (Component) => {
ReactDOM.render(
<AppContainer>
<HashRouter>
<Component/>
</HashRouter>
</AppContainer>,
document.getElementById('react-app-root')
);
};
render(App);
/*eslint-disable */
if (module.hot) {
module.hot.accept('./components/App', () => {
render(App);
});
}
/*eslint-enable */
Notice the AppContainer component imported from react-hot-loader that wraps your app in ReactDOM.render. Also, sometimes eslint can interfere with hot reloading which is why it is disabled and then enabled again at the bottom of the file.
I hope this helps.
I've built a Node/React/Webpack app and just deployed it. Everything works just like on localhost for my desktop (Ubuntu 16.04 with Chrome and Firefox) and from an Android Galaxy Core phone using Chrome, but on an iPhone 5S using Safari and Firefox I don't get anything except the name of the app showing up in the title of the tab.
I don't think it's a case of CSS messing with me - I tried to go directly to one of the internal pages and it didn't redirect me to the main page like it should have, so I think it isn't loading at all.
Are there any common gotchas with this? This is the second Node/React/Webpack app I've built, using pretty similar methods, and the first one did fine on everything.
Here is my package.json file - if there's anything else that would be helpful to see just ask.
{
"name": "last-minute",
"version": "1.0.0",
"description": "connect to others nearby for last-minute hanging out",
"main": "webpack.prod.js",
"engines": {
"node": "9.5.0",
"npm": "6.1.0"
},
"scripts": {
"test": "jest --config jest.config.json",
"start": "node server/server.js",
"build": "webpack --config webpack.prod.js",
"dev": "webpack --config webpack.dev.js --mode development && node server/server.js",
"light": "webpack --config webpack.light.js --mode development && node light-server/style-server.js"
},
"author": "Doug Sauve",
"license": "ISC",
"dependencies": {
"#babel/core": "^7.0.0-beta.44",
"#babel/preset-env": "^7.0.0-beta.44",
"#babel/preset-react": "^7.0.0-beta.44",
"#google/maps": "^0.4.6",
"babel-loader": "^8.0.0-beta.2",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-env": "^1.7.0",
"bcryptjs": "^2.4.3",
"css-loader": "^0.28.11",
"enzyme": "^3.3.0",
"enzyme-adapter-react-16": "^1.1.1",
"express": "^4.16.2",
"google-maps-react": "^2.0.2",
"jest": "^22.4.4",
"moment": "^2.22.1",
"mongoose": "^5.0.14",
"node-sass": "^4.9.1",
"nodemailer": "^4.6.5",
"normalize.css": "^8.0.0",
"raf": "^3.4.0",
"react": "^16.3.1",
"react-dom": "^16.3.1",
"react-geocode": "0.0.9",
"react-redux": "^5.0.7",
"react-test-renderer": "^16.0.0",
"redux": "^4.0.0",
"sass-loader": "^6.0.7",
"socket.io": "^2.1.0",
"style-loader": "^0.20.3",
"validator": "^10.2.0",
"webpack": "^4.4.1",
"webpack-cli": "^2.0.13",
"webpack-merge": "^4.1.2"
}
}
webpack.common.js
const path = require('path');
const webpack = require('webpack');
module.exports = {
entry: ['babel-polyfill', path.join(__dirname, `/src/main.js`)],
output: {
path: path.join(__dirname, `/public`),
filename: `bundle.js`
},
module: {
rules: [
{
test: /\.js$/,
exclude: [
path.join(__dirname, '/node_modules'),
],
use: {
loader: 'babel-loader',
options: {
presets: ['#babel/preset-env', '#babel/preset-react'],
plugins: [
['transform-class-properties', { 'spec': true }],
['transform-object-rest-spread']
]
}
}
}, {
test: /\.s?css$/,
use: [
{ loader: 'style-loader' },
{ loader: 'css-loader' },
{ loader: 'sass-loader' }
]
}
]
}
};
webpack.prod.js
const merge = require ('webpack-merge');
const webpack = require ('webpack');
const common = require ('./webpack.common.js');
module.exports = merge(common, {
mode: 'production',
plugins: [
new webpack.DefinePlugin({
'process.env.NODE_ENV': JSON.stringify('production')
})
]
});
It seems to be an issue on older versions of iOS, not sure what the breakpoint is.
I want to use MatPaginatorModule in my angular t project but i am getting error:
Can't bind to 'pageSize' since it isn't a known property of 'mat-paginator'
1. If 'mat-paginator' is an Angular component and it has 'pageSize' input, then verify that it is part of this module.
...............
html
<mat-paginator #paginator
[pageSize]="10"
[pageSizeOptions]="[5, 10, 20]"
[showFirstLastButtons]="true">
</mat-paginator>
i have imported module in my app.module.ts
import { BrowserModule } from '#angular/platform-browser';
import { NgModule } from '#angular/core';
import { AppComponent } from './app.component';
import { GlobalModule } from './global/global.module';
import { ProtectedModule} from './protetcted/protect-module.component';
import { AppRoutingModule } from './app.routing.module';
// import { MatTableModule } from '#angular/material/table';
import { MatPaginatorModule } from '#angular/material';
#NgModule({
declarations: [
AppComponent,
],
imports: [
BrowserModule,
GlobalModule,
ProtectedModule,
AppRoutingModule,
// MatTableModule,
MatPaginatorModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
i am using angular5
package.json
{
"name": "eci",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "node app.js",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"#angular/animations": "^5.2.10",
"#angular/cdk": "^5.2.5",
"#angular/common": "^5.2.0",
"#angular/compiler": "^5.2.0",
"#angular/core": "^5.2.0",
"#angular/forms": "^5.2.0",
"#angular/http": "^5.2.0",
"#angular/material": "^5.2.5",
"#angular/platform-browser": "^5.2.0",
"#angular/platform-browser-dynamic": "^5.2.0",
"#angular/router": "^5.2.0",
"angular-font-awesome": "^3.1.2",
"bootstrap": "^4.1.0",
"cfenv": "^1.0.4",
"core-js": "^2.4.1",
"express": "^4.15.0",
"font-awesome": "^4.7.0",
"jquery": "^3.3.1",
"rxjs": "^5.5.6",
"zone.js": "^0.8.19"
},
"devDependencies": {
"#angular/cli": "~1.7.2",
"#angular/compiler-cli": "^5.2.0",
"#angular/language-service": "^5.2.0",
"#types/jasmine": "~2.8.3",
"#types/jasminewd2": "~2.0.2",
"#types/jquery": "^3.3.1",
"#types/node": "~6.0.60",
"codelyzer": "^4.0.1",
"jasmine-core": "~2.8.0",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~2.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"ts-node": "~4.1.0",
"tslint": "~5.9.1",
"typescript": "~2.5.3"
}
}
#Kumail,
Everything looks fine from the snippets you posted.
Though this error will occur only when the required module is not linked. The only reason I could think of is that, you might not have saved app.module.ts file after modifications. I did follow all the steps to integrate a MatPaginatorModule in a test project and it worked. Then I mocked to include that module in app.module.ts but not saved the changes. This time I got the error you posted. Try saving, If you could have missed after modifying app.module.ts file.
If the error is coming while doing testing, then the imports are needed in the test/spec file. (app.component.spec.ts)