Skip to content

Commit c785633

Browse files
committed
Merge pull request #1 from nikrolls/edge-compatibility
Edge compatibility
2 parents e494f29 + ed652ae commit c785633

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

extension/js/background.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
*/
3232

3333
/*jshint eqeqeq:true, forin:true, strict:true */
34-
/*global chrome, console */
34+
/*global browser, chrome, console */
3535

3636
(function () {
3737

@@ -47,6 +47,10 @@
4747
TYPE_NULL = 6
4848
;
4949

50+
function getBrowser() {
51+
return typeof browser !== 'undefined' ? browser : chrome;
52+
}
53+
5054
// Utility functions
5155
function removeComments (str) {
5256
str = ('__' + str + '__').split('');
@@ -395,7 +399,7 @@
395399
}
396400

397401
// Listen for requests from content pages wanting to set up a port
398-
chrome.extension.onConnect.addListener(function(port) {
402+
getBrowser().runtime.onConnect.addListener(function(port) {
399403

400404
if (port.name !== 'jf') {
401405
console.log('JSON Formatter error - unknown port name '+port.name, port) ;

extension/js/content.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,16 @@
3131
*/
3232

3333
/*jshint eqeqeq:true, forin:true, strict:true */
34-
/*global chrome, console */
34+
/*global browser, chrome, console */
3535

3636
(function() {
3737

3838
"use strict" ;
3939

40+
function getBrowser() {
41+
return typeof browser !== 'undefined' ? browser : chrome;
42+
}
43+
4044
var jfContent,
4145
pre,
4246
jfStyleEl,
@@ -51,7 +55,7 @@
5155

5256
// Open the port "jf" now, ready for when we need it
5357
// console.time('established port') ;
54-
port = chrome.extension.connect({name: 'jf'}) ;
58+
port = getBrowser().runtime.connect({name: 'jf'}) ;
5559

5660
// Add listener to receive response from BG when ready
5761
port.onMessage.addListener( function (msg) {

extension/manifest.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
{
22
"name": "JSON Formatter",
3-
"version": "0.6.0",
3+
"version": "0.6.1",
44
"manifest_version": 2,
55
"description": "Makes JSON easy to read. Open source.",
6-
"homepage_url": "https://github.com/callumlocke/json-formatter",
7-
"minimum_chrome_version": "21",
6+
"homepage_url": "https://github.com/nikrolls/json-formatter",
7+
"author": "Nik Rolls, Callum Locke",
8+
"minimum_edge_version": "38",
89
"icons": {
910
"128": "icons/128.png",
1011
"32": "icons/32.png"
1112
},
1213
"background": {
13-
"scripts": ["js/background.js"]
14+
"scripts": ["js/background.js"],
15+
"persistent": false
1416
},
1517
"content_scripts": [
1618
{ "matches": ["<all_urls>"], "js": ["js/content.js"], "run_at": "document_start" }

0 commit comments

Comments
 (0)