├── .gitignore ├── LICENSE ├── README.md ├── build ├── hook.js ├── img │ ├── iconx128.png │ ├── iconx16.png │ └── iconx48.png ├── js │ └── wechat-js-bridge-mockup.js └── manifest.json ├── gulpfile.js └── package.json /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | node_modules/ 4 | 5 | build.zip 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Albert 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 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | WeChat WebView Debug 2 | == 3 | 4 | 模拟微信应用中打开网页时原生注入的 WeixinJSBridge 对象,方便在开发环境中调试 5 | 6 | [Install from Chrome Web Store](https://chrome.google.com/webstore/detail/wechat-webview-debug/cdhcdakjeodplpdbfjklldchfnhaepja) 7 | 8 | 参考文献 9 | -- 10 | 11 | 1. 微信 JS-SDK 说明文档 http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html 12 | 2. 微信 JS-SDK Demo http://demo.open.weixin.qq.com/jssdk 13 | 14 | MIT License 15 | == 16 | 17 | -------------------------------------------------------------------------------- /build/hook.js: -------------------------------------------------------------------------------- 1 | if (/MicroMessenger/i.test(window.navigator.userAgent)) { 2 | const script = document.createElement('script') 3 | script.src = chrome.extension.getURL('js/wechat-js-bridge-mockup.js'); 4 | document.documentElement.appendChild(script); 5 | script.parentNode.removeChild(script); 6 | console.debug('wechat-webview-debug is ready'); 7 | } 8 | -------------------------------------------------------------------------------- /build/img/iconx128.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechatpivot/wechat-webview-debug/b60a8b19b4d4c740cdb9181598370c95ce26f323/build/img/iconx128.png -------------------------------------------------------------------------------- /build/img/iconx16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechatpivot/wechat-webview-debug/b60a8b19b4d4c740cdb9181598370c95ce26f323/build/img/iconx16.png -------------------------------------------------------------------------------- /build/img/iconx48.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/wechatpivot/wechat-webview-debug/b60a8b19b4d4c740cdb9181598370c95ce26f323/build/img/iconx48.png -------------------------------------------------------------------------------- /build/js/wechat-js-bridge-mockup.js: -------------------------------------------------------------------------------- 1 | (function () { 2 | var userAgent = navigator.userAgent.toLowerCase() 3 | var isWeixin = -1 != userAgent.indexOf("micromessenger"); 4 | var isAndroid = -1 != userAgent.indexOf("android"); 5 | var isIOS = -1 != userAgent.indexOf("iphone") || -1 != userAgent.indexOf("ipad"); 6 | 7 | 8 | var LAZY_INVOKE = { 9 | 'menu:share:appmessage': null, 10 | 'menu:share:timeline': null, 11 | }; 12 | 13 | 14 | var Bridge = { 15 | invoke: function (apiName, conf, callback) { 16 | var result = { 17 | err_code: 'WILL_DELETE', 18 | err_desc: 'WILL_DELETE', 19 | err_detail: 'WILL_DELETE', 20 | 21 | err_msg: apiName + ':ok', 22 | }; 23 | 24 | var MOCKUP_RESULT = window.WEIXIN_JS_BRIDGE_INVOKE || {}; 25 | 26 | if (apiName === 'geoLocation') { 27 | var mock = MOCKUP_RESULT[apiName] || {}; 28 | for (var k in mock) { 29 | result[k] = mock[k]; 30 | } 31 | } else if (apiName == 'scanQRCode' && isIOS) { 32 | // ** ios 扫码会返回一个很反人类的行为, 33 | // 微信官方在 js sdk 中通过检查 isIOS 抹平了这个接口的不一致性 34 | // 因此模拟的时候也要把这个反人类的行为模拟出来 35 | result.resultStr = JSON.stringify({ 36 | scan_code: { 37 | scan_result: MOCKUP_RESULT[apiName] || '', 38 | }, 39 | }); 40 | } else { 41 | if (MOCKUP_RESULT[apiName]) { 42 | result.resultStr = MOCKUP_RESULT[apiName]; 43 | } 44 | } 45 | 46 | callback(result); 47 | }, 48 | 49 | on: function (apiName, callback) { 50 | var MOCKUP_RESULT = window.WEIXIN_JS_BRIDGE_ON || {}; 51 | 52 | if (apiName in LAZY_INVOKE) { 53 | LAZY_INVOKE[apiName] = function () { 54 | callback({ 55 | err_code: 'WILL_DELETE', 56 | err_desc: 'WILL_DELETE', 57 | err_detail: 'WILL_DELETE', 58 | 59 | err_msg: 'ok', 60 | 61 | resultStr: MOCKUP_RESULT[apiName] || '{}' 62 | }); 63 | }; 64 | } else { 65 | callback({ 66 | err_code: 'WILL_DELETE', 67 | err_desc: 'WILL_DELETE', 68 | err_detail: 'WILL_DELETE', 69 | 70 | err_msg: 'ok', 71 | 72 | resultStr: MOCKUP_RESULT[apiName] || '{}' 73 | }); 74 | } 75 | }, 76 | }; 77 | 78 | 79 | function lazyInvoke(api) { 80 | // ** from jweixin 81 | var API_NAMES = { 82 | config: "preVerifyJSAPI", 83 | onMenuShareTimeline: "menu:share:timeline", 84 | onMenuShareAppMessage: "menu:share:appmessage", 85 | onMenuShareQQ: "menu:share:qq", 86 | onMenuShareWeibo: "menu:share:weiboApp", 87 | onMenuShareQZone: "menu:share:QZone", 88 | previewImage: "imagePreview", 89 | getLocation: "geoLocation", 90 | openProductSpecificView: "openProductViewWithPid", 91 | addCard: "batchAddCard", 92 | openCard: "batchViewCard", 93 | chooseWXPay: "getBrandWCPayRequest", 94 | }; 95 | 96 | var lazyKey = API_NAMES[api]; 97 | var lazyCallback = LAZY_INVOKE[lazyKey]; 98 | 99 | if (lazyCallback) { 100 | lazyCallback(); 101 | LAZY_INVOKE[lazyKey] = null; 102 | } 103 | }; 104 | 105 | 106 | window.WeixinJSBridge = Bridge; 107 | 108 | 109 | var share = {}; 110 | 111 | Object.defineProperty(share, 'moment', { 112 | get: function () { 113 | console.debug('分享到朋友圈'); 114 | lazyInvoke('onMenuShareTimeline'); 115 | return null; 116 | }, 117 | }); 118 | 119 | Object.defineProperty(share, 'chat', { 120 | get: function () { 121 | console.debug('分享到聊天'); 122 | lazyInvoke('onMenuShareAppMessage'); 123 | return null; 124 | }, 125 | }); 126 | 127 | 128 | 129 | var command = { 130 | share: share, 131 | }; 132 | 133 | 134 | var head = window.head || {}; 135 | head.wechat = command; 136 | window.head = head; 137 | }()); 138 | -------------------------------------------------------------------------------- /build/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "WeChat WebView Debug", 3 | "version": "0.1.0", 4 | "description": "Chrome devtools extension for debugging webapp in WeChat", 5 | "manifest_version": 2, 6 | "icons": { 7 | "16": "img/iconx16.png", 8 | "48": "img/iconx48.png", 9 | "128": "img/iconx128.png" 10 | }, 11 | 12 | "content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'", 13 | 14 | "permissions": [ 15 | "tabs", 16 | "http://*/*", 17 | "https://*/*" 18 | ], 19 | 20 | "web_accessible_resources": [ 21 | "js/*.js" 22 | ], 23 | 24 | "content_scripts": [ 25 | { 26 | "matches": [""], 27 | "js": ["hook.js"], 28 | "run_at": "document_start" 29 | } 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'); 2 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wechat-webview-debug", 3 | "version": "0.2.0", 4 | "description": "a mockup of WeixinJSBridge in the app", 5 | "main": "index.js", 6 | "scripts": { 7 | }, 8 | "repository": { 9 | "type": "git", 10 | "url": "https://github.com/wechat-developer/wechat-webview-debug.git" 11 | }, 12 | "keywords": [ 13 | "wechat", 14 | "weixin", 15 | "WeixinJSBridge", 16 | "jWeixin" 17 | ], 18 | "author": "hbrls", 19 | "license": "MIT", 20 | "bugs": { 21 | "url": "https://github.com/wechat-developer/wechat-webview-debug/issues" 22 | }, 23 | "homepage": "https://github.com/wechat-developer/wechat-webview-debug", 24 | "devDependencies": { 25 | "gulp": "3.9.1" 26 | } 27 | } 28 | --------------------------------------------------------------------------------