├── .prettierrc ├── CHANGELOG.md ├── package.json ├── LICENSE ├── MMM-WebView.js ├── .gitignore └── README.md /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "printWidth": 120, 3 | "tabWidth": 2, 4 | "singleQuote": true, 5 | "trailingComma": "es5", 6 | "semi": true 7 | } 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | 5 | The format is based on [Keep a Changelog](http://keepachangelog.com/) 6 | and this project adheres to [Semantic Versioning](http://semver.org/). 7 | 8 | ## 1.0.0 - 2021-09-14 9 | 10 | ### Initial release of MMM-WebView 11 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "MMM-WebView", 3 | "version": "1.0.0", 4 | "description": "The simple WebView module for MagicMirror²", 5 | "repository": { 6 | "type": "git", 7 | "url": "git+https://github.com/Iketaki/MMM-WebView" 8 | }, 9 | "keywords": [ 10 | "magic mirror", 11 | "magicmirror", 12 | "magicmirror2", 13 | "smart mirror", 14 | "webview" 15 | ], 16 | "author": "Shunta Iketaki", 17 | "license": "MIT", 18 | "homepage": "https://github.com/Iketaki/MMM-WebView", 19 | "dependencies": {}, 20 | "devDependencies": { 21 | "prettier": "2.4.0" 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Shunta Iketaki 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MMM-WebView.js: -------------------------------------------------------------------------------- 1 | /* Magic Mirror 2 | * Module: MMM-WebView 3 | * 4 | * By Shunta Iketaki https://twitter.com/Iketaki 5 | * MIT Licensed. 6 | */ 7 | 8 | const WEBVIEW_ID = 'mmm-webview'; 9 | 10 | Module.register('MMM-WebView', { 11 | defaults: { 12 | url: 'https://www.google.com/', 13 | height: '640px', 14 | width: '480px', 15 | autoRefresh: false, 16 | autoRefreshInterval: 10 * 60 * 1000, 17 | loadedJS: undefined, 18 | }, 19 | start: function () { 20 | if (this.config.autoRefresh) { 21 | setInterval(() => { 22 | //Electron.session.defaultSession.clearCache(() => {}); 23 | //this.updateDom(); 24 | const webview = document.getElementById(WEBVIEW_ID); 25 | webview.reloadIgnoringCache(); 26 | }, this.config.autoRefreshInterval); 27 | } 28 | }, 29 | getDom: function () { 30 | let wrapper = document.createElement('div'); 31 | wrapper.id = 'mmm-webview-wrapper'; 32 | wrapper.innerHTML = ``; 33 | return wrapper; 34 | }, 35 | notificationReceived: function (notification, payload, sender) { 36 | if (notification == 'MODULE_DOM_CREATED') { 37 | if (this.config.loadedJS && this.config.loadedJS.length > 0) { 38 | const webview = document.getElementById(WEBVIEW_ID); 39 | if (webview) { 40 | webview.addEventListener('did-finish-load', () => { 41 | webview.executeJavaScript(this.config.loadedJS); 42 | }); 43 | } else { 44 | // TODO: Show Error 45 | } 46 | } 47 | } 48 | }, 49 | }); 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | 2 | # Created by https://www.toptal.com/developers/gitignore/api/node,visualstudiocode 3 | # Edit at https://www.toptal.com/developers/gitignore?templates=node,visualstudiocode 4 | 5 | ### Node ### 6 | # Logs 7 | logs 8 | *.log 9 | npm-debug.log* 10 | yarn-debug.log* 11 | yarn-error.log* 12 | lerna-debug.log* 13 | .pnpm-debug.log* 14 | 15 | # Diagnostic reports (https://nodejs.org/api/report.html) 16 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 17 | 18 | # Runtime data 19 | pids 20 | *.pid 21 | *.seed 22 | *.pid.lock 23 | 24 | # Directory for instrumented libs generated by jscoverage/JSCover 25 | lib-cov 26 | 27 | # Coverage directory used by tools like istanbul 28 | coverage 29 | *.lcov 30 | 31 | # nyc test coverage 32 | .nyc_output 33 | 34 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 35 | .grunt 36 | 37 | # Bower dependency directory (https://bower.io/) 38 | bower_components 39 | 40 | # node-waf configuration 41 | .lock-wscript 42 | 43 | # Compiled binary addons (https://nodejs.org/api/addons.html) 44 | build/Release 45 | 46 | # Dependency directories 47 | node_modules/ 48 | jspm_packages/ 49 | 50 | # Snowpack dependency directory (https://snowpack.dev/) 51 | web_modules/ 52 | 53 | # TypeScript cache 54 | *.tsbuildinfo 55 | 56 | # Optional npm cache directory 57 | .npm 58 | 59 | # Optional eslint cache 60 | .eslintcache 61 | 62 | # Microbundle cache 63 | .rpt2_cache/ 64 | .rts2_cache_cjs/ 65 | .rts2_cache_es/ 66 | .rts2_cache_umd/ 67 | 68 | # Optional REPL history 69 | .node_repl_history 70 | 71 | # Output of 'npm pack' 72 | *.tgz 73 | 74 | # Yarn Integrity file 75 | .yarn-integrity 76 | 77 | # dotenv environment variables file 78 | .env 79 | .env.test 80 | .env.production 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # Serverless directories 104 | .serverless/ 105 | 106 | # FuseBox cache 107 | .fusebox/ 108 | 109 | # DynamoDB Local files 110 | .dynamodb/ 111 | 112 | # TernJS port file 113 | .tern-port 114 | 115 | # Stores VSCode versions used for testing VSCode extensions 116 | .vscode-test 117 | 118 | # yarn v2 119 | .yarn/cache 120 | .yarn/unplugged 121 | .yarn/build-state.yml 122 | .yarn/install-state.gz 123 | .pnp.* 124 | 125 | ### VisualStudioCode ### 126 | .vscode/* 127 | !.vscode/settings.json 128 | !.vscode/tasks.json 129 | !.vscode/launch.json 130 | !.vscode/extensions.json 131 | *.code-workspace 132 | 133 | # Local History for Visual Studio Code 134 | .history/ 135 | 136 | ### VisualStudioCode Patch ### 137 | # Ignore all local history of files 138 | .history 139 | .ionide 140 | 141 | # End of https://www.toptal.com/developers/gitignore/api/node,visualstudiocode 142 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MMM-WebView: A WebView module for MagicMirror² 2 | 3 | This is a module for the [MagicMirror²](https://github.com/MichMich/MagicMirror/). 4 | 5 | MMM-WebView allows you to add a webview which can display any url. 6 | 7 | This module uses the [Electron's \ tag](https://www.electronjs.org/docs/api/webview-tag) instead of `