1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-11-24 08:12:24 +02:00

Clipper: Completed doc and simplified logic to get clipper port to make it easier to use by third-party

This commit is contained in:
Laurent Cozic 2018-06-18 18:54:48 +01:00
parent 1f3a1c49df
commit 21ef8da45f
5 changed files with 183 additions and 338 deletions

View File

@ -1,166 +1,20 @@
const reservedPorts = [1024, 1027, 1028, 1029, 1058, 1059, 1080, 1085, 1098, 1099, 1109, 1119, 1167, 1194, 1198, 1214, 1220, 1234, 1241, 1270, 1293, 1311, 1314, 1337, 1341, 1344,
1352, 1360, 1414, 1417, 1418, 1419, 1420, 1431, 1433, 1434, 1492, 1494, 1500, 1501, 1503, 1512, 1513, 1521, 1524, 1527, 1533, 1547, 1550, 1581, 1582, 1583, 1589, 1604, 1626, 1627,
1628, 1629, 1645, 1646, 1666, 1677, 1688, 1701, 1707, 1716, 1719, 1720, 1723, 1755, 1761, 1783, 1801, 1812, 1813, 1863, 1880, 1883, 1900, 1935, 1967, 1970, 1972, 1984, 1985, 1998,
2000, 2010, 2033, 2049, 2056, 2080, 2082, 2083, 2086, 2087, 2095, 2096, 2100, 2101, 2102, 2103, 2104, 2123, 2142, 2152, 2159, 2181, 2195, 2196, 2210, 2211, 2221, 2222, 2261, 2262,
2266, 2305, 2351, 2368, 2369, 2370, 2372, 2375, 2376, 2377, 2379, 2380, 2399, 2401, 2404, 2424, 2427, 2447, 2480, 2483, 2484, 2535, 2541, 2546, 2593, 2598, 2599, 2638, 2710, 2727,
2809, 2811, 2827, 2944, 2945, 2947, 2948, 2949, 2967, 3000, 3004, 3020, 3050, 3052, 3074, 3101, 3128, 3225, 3233, 3260, 3268, 3269, 3283, 3290, 3305, 3306, 3313, 3316, 3323, 3332,
3333, 3351, 3386, 3389, 3396, 3412, 3423, 3424, 3455, 3478, 3479, 3480, 3483, 3493, 3516, 3527, 3535, 3544, 3632, 3645, 3659, 3667, 3689, 3690, 3702, 3724, 3725, 3768, 3784, 3785,
3799, 3804, 3825, 3826, 3830, 3835, 3856, 3868, 3872, 3880, 3900, 3960, 3962, 3978, 3979, 3999, 4000, 4001, 4018, 4035, 4045, 4050, 4069, 4089, 4090, 4093, 4096, 4105, 4111, 4116,
4125, 4172, 4190, 4198, 4201, 4222, 4226, 4242, 4243, 4244, 4303, 4321, 4352, 4444, 4486, 4488, 4500, 4502, 4505, 4534, 4560, 4567, 4569, 4604, 4605, 4610, 4662, 4664, 4672, 4711,
4713, 4728, 4730, 4739, 4747, 4750, 4753, 4840, 4843, 4847, 4848, 4894, 4949, 4950, 5000, 5001, 5002, 5003, 5004, 5005, 5010, 5011, 5031, 5037, 5048, 5050, 5051, 5060, 5061, 5062,
5064, 5065, 5070, 5084, 5085, 5093, 5099, 5104, 5121, 5124, 5125, 5150, 5151, 5154, 5190, 5201, 5222, 5223, 5228, 5242, 5243, 5246, 5247, 5269, 5280, 5281, 5298, 5310, 5349, 5351,
5353, 5355, 5357, 5358, 5394, 5402, 5405, 5412, 5413, 5417, 5421, 5432, 5433, 5445, 5480, 5481, 5495, 5498, 5499, 5500, 5501, 5517, 5550, 5554, 5555, 5556, 5568, 5601, 5631, 5632,
5656, 5666, 5667, 5670, 5672, 5678, 5683, 5701, 5718, 5719, 5722, 5723, 5724, 5741, 5742, 5800, 5900, 5931, 5938, 5984, 5985, 5986, 5988, 6000, 6001, 6002, 6003, 6004, 6005, 6006,
6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024, 6025, 6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036,
6037, 6038, 6039, 6040, 6041, 6042, 6043, 6044, 6045, 6046, 6047, 6048, 6049, 6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061, 6062, 6063, 6086, 6100, 6101,
6110, 6111, 6112, 6113, 6136, 6159, 6200, 6201, 6225, 6227, 6240, 6244, 6255, 6257, 6260, 6262, 6343, 6346, 6347, 6350, 6379, 6389, 6432, 6436, 6437, 6444, 6445, 6463, 6502, 6513,
6514, 6515, 6543, 6556, 6560, 6566, 6571, 6600, 6601, 6602, 6619, 6622, 6653, 6660, 6665, 6679, 6690, 6697, 6699, 6715, 6771, 6783, 6789, 6869, 6881, 6888, 6889, 6891, 6901, 6902,
6969, 6970, 7000, 7001, 7002, 7005, 7006, 7010, 7022, 7023, 7025, 7047, 7070, 7133, 7144, 7145, 7171, 7262, 7272, 7306, 7307, 7312, 7396, 7400, 7401, 7402, 7471, 7473, 7474, 7478,
7542, 7547, 7575, 7624, 7631, 7634, 7652, 7655, 7656, 7670, 7687, 7707, 7717, 7777, 7831, 7880, 7890, 7915, 7935, 7946, 7990, 8000, 8005, 8006, 8007, 8008, 8009, 8042, 8069, 8070,
8074, 8075, 8080, 8088, 8089, 8090, 8091, 8092, 8111, 8112, 8116, 8118, 8123, 8139, 8140, 8172, 8184, 8194, 8200, 8222, 8243, 8245, 8280, 8281, 8291, 8303, 8332, 8333, 8337, 8384,
8388, 8443, 8444, 8484, 8500, 8530, 8531, 8580, 8629, 8642, 8691, 8767, 8834, 8840, 8880, 8883, 8887, 8888, 8889, 8983, 8997, 8998, 8999, 9000, 9001, 9002, 9006, 9030, 9042, 9043,
9050, 9060, 9080, 9090, 9091, 9092, 9100, 9101, 9102, 9103, 9119, 9150, 9191, 9199, 9200, 9217, 9293, 9300, 9303, 9306, 9309, 9312, 9332, 9333, 9339, 9389, 9418, 9419, 9420, 9421,
9422, 9425, 9443, 9535, 9536, 9600, 9675, 9676, 9695, 9785, 9800, 9875, 9898, 9899, 9981, 9982, 9987, 9993, 9997, 9999, 10000, 10001, 10009, 10010, 10024, 10025, 10042, 10050, 10051,
10080, 10110, 10172, 10200, 10201, 10212, 10308, 10480, 10505, 10514, 10823, 10891, 10933, 11001, 11111, 11112, 11211, 11214, 11215, 11235, 11311, 11371, 11753, 12012, 12013, 12035,
12043, 12046, 12201, 12222, 12223, 12345, 12443, 12489, 12975, 13000, 13008, 13075, 13720, 13721, 13724, 13782, 13783, 13785, 13786, 14550, 14567, 15000, 15345, 15441, 15567, 15672,
16000, 16080, 16200, 16225, 16250, 16261, 16300, 16384, 16385, 16386, 16387, 16393, 16394, 16395, 16396, 16397, 16398, 16399, 16400, 16401, 16402, 16403, 16404, 16405, 16406, 16407,
16408, 16409, 16410, 16411, 16412, 16413, 16414, 16415, 16416, 16417, 16418, 16419, 16420, 16421, 16422, 16423, 16424, 16425, 16426, 16427, 16428, 16429, 16430, 16431, 16432, 16433,
16434, 16435, 16436, 16437, 16438, 16439, 16440, 16441, 16442, 16443, 16444, 16445, 16446, 16447, 16448, 16449, 16450, 16451, 16452, 16453, 16454, 16455, 16456, 16457, 16458, 16459,
16460, 16461, 16462, 16463, 16464, 16465, 16466, 16467, 16468, 16469, 16470, 16471, 16472, 16482, 16567, 17011, 17500, 18091, 18092, 18104, 18200, 18201, 18206, 18300, 18301, 18306,
18333, 18400, 18401, 18505, 18506, 18605, 18606, 19000, 19001, 19132, 19150, 19226, 19294, 19295, 19302, 19812, 19813, 19814, 19999, 20000, 20560, 20595, 20808, 21025, 22000, 22136,
22222, 23073, 23399, 23513, 24441, 24444, 24465, 24554, 24800, 24842, 25565, 25575, 25826, 26000, 26900, 27000, 27016, 27017, 27031, 27036, 27037, 27374, 27500, 27888, 27901, 27950,
27960, 28001, 28015, 28770, 28785, 28852, 28910, 28960, 29000, 29070, 29900, 29920, 30564, 31337, 31416, 31438, 31457, 32137, 32400, 32764, 32887, 32976, 33434, 33848, 34000, 34197,
35357, 37008, 40000, 43110, 43594, 44405, 44818, 47001, 47808, 49151];
// From https://github.com/coverslide/node-alea
const AleaModule = function () {
// importState to sync generator states
Alea.importState = function(i){
var random = new Alea();
random.importState(i);
return random;
function randomClipperPort(state, env) {
const startPorts = {
prod: 41184,
dev: 27583,
};
return Alea;
const startPort = env === 'prod' ? startPorts.prod : startPorts.dev;
function Alea() {
return (function(args) {
// Johannes Baagøe <baagoe@baagoe.com>, 2010
var s0 = 0;
var s1 = 0;
var s2 = 0;
var c = 1;
if (args.length === 0) {
args = [+new Date()];
}
var mash = Mash();
s0 = mash(' ');
s1 = mash(' ');
s2 = mash(' ');
for (var i = 0; i < args.length; i++) {
s0 -= mash(args[i]);
if (s0 < 0) {
s0 += 1;
}
s1 -= mash(args[i]);
if (s1 < 0) {
s1 += 1;
}
s2 -= mash(args[i]);
if (s2 < 0) {
s2 += 1;
}
}
mash = null;
var random = function() {
var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32
s0 = s1;
s1 = s2;
return s2 = t - (c = t | 0);
};
random.uint32 = function() {
return random() * 0x100000000; // 2^32
};
random.fract53 = function() {
return random() +
(random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
};
random.version = 'Alea 0.9';
random.args = args;
// my own additions to sync state between two generators
random.exportState = function(){
return [s0, s1, s2, c];
};
random.importState = function(i){
s0 = +i[0] || 0;
s1 = +i[1] || 0;
s2 = +i[2] || 0;
c = +i[3] || 0;
};
return random;
} (Array.prototype.slice.call(arguments)));
if (!state) {
state = { offset: 0 };
} else {
state.offset++;
}
function Mash() {
var n = 0xefc8249d;
state.port = startPort + state.offset;
var mash = function(data) {
data = data.toString();
for (var i = 0; i < data.length; i++) {
n += data.charCodeAt(i);
var h = 0.02519603282416938 * n;
n = h >>> 0;
h -= n;
h *= n;
n = h >>> 0;
h -= n;
n += h * 0x100000000; // 2^32
}
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
};
mash.version = 'Mash 0.9';
return mash;
}
return state;
}
const Alea = AleaModule()
function findClipperPort(state, mode = 'prod') {
const seed = mode === 'prod' ? 1867 : 2001;
const minPort = 1024
const maxPort = 49151
let prng = null;
if (!state) {
prng = new Alea(seed)
state = { prng: prng }
} else {
prng = state.prng;
}
const randomPort = () => {
return minPort + Math.floor(prng() * ((maxPort + 1) - minPort));
}
let port = null;
for (let i = 0; i < maxPort; i++) {
port = randomPort();
if (reservedPorts.indexOf(port) < 0) break;
}
if (!port) throw new Error('Cannot find a non-reserved port');
state.port = port;
return state;
}
module.exports = findClipperPort;
module.exports = randomClipperPort;

View File

@ -1,164 +1,18 @@
const reservedPorts = [1024, 1027, 1028, 1029, 1058, 1059, 1080, 1085, 1098, 1099, 1109, 1119, 1167, 1194, 1198, 1214, 1220, 1234, 1241, 1270, 1293, 1311, 1314, 1337, 1341, 1344,
1352, 1360, 1414, 1417, 1418, 1419, 1420, 1431, 1433, 1434, 1492, 1494, 1500, 1501, 1503, 1512, 1513, 1521, 1524, 1527, 1533, 1547, 1550, 1581, 1582, 1583, 1589, 1604, 1626, 1627,
1628, 1629, 1645, 1646, 1666, 1677, 1688, 1701, 1707, 1716, 1719, 1720, 1723, 1755, 1761, 1783, 1801, 1812, 1813, 1863, 1880, 1883, 1900, 1935, 1967, 1970, 1972, 1984, 1985, 1998,
2000, 2010, 2033, 2049, 2056, 2080, 2082, 2083, 2086, 2087, 2095, 2096, 2100, 2101, 2102, 2103, 2104, 2123, 2142, 2152, 2159, 2181, 2195, 2196, 2210, 2211, 2221, 2222, 2261, 2262,
2266, 2305, 2351, 2368, 2369, 2370, 2372, 2375, 2376, 2377, 2379, 2380, 2399, 2401, 2404, 2424, 2427, 2447, 2480, 2483, 2484, 2535, 2541, 2546, 2593, 2598, 2599, 2638, 2710, 2727,
2809, 2811, 2827, 2944, 2945, 2947, 2948, 2949, 2967, 3000, 3004, 3020, 3050, 3052, 3074, 3101, 3128, 3225, 3233, 3260, 3268, 3269, 3283, 3290, 3305, 3306, 3313, 3316, 3323, 3332,
3333, 3351, 3386, 3389, 3396, 3412, 3423, 3424, 3455, 3478, 3479, 3480, 3483, 3493, 3516, 3527, 3535, 3544, 3632, 3645, 3659, 3667, 3689, 3690, 3702, 3724, 3725, 3768, 3784, 3785,
3799, 3804, 3825, 3826, 3830, 3835, 3856, 3868, 3872, 3880, 3900, 3960, 3962, 3978, 3979, 3999, 4000, 4001, 4018, 4035, 4045, 4050, 4069, 4089, 4090, 4093, 4096, 4105, 4111, 4116,
4125, 4172, 4190, 4198, 4201, 4222, 4226, 4242, 4243, 4244, 4303, 4321, 4352, 4444, 4486, 4488, 4500, 4502, 4505, 4534, 4560, 4567, 4569, 4604, 4605, 4610, 4662, 4664, 4672, 4711,
4713, 4728, 4730, 4739, 4747, 4750, 4753, 4840, 4843, 4847, 4848, 4894, 4949, 4950, 5000, 5001, 5002, 5003, 5004, 5005, 5010, 5011, 5031, 5037, 5048, 5050, 5051, 5060, 5061, 5062,
5064, 5065, 5070, 5084, 5085, 5093, 5099, 5104, 5121, 5124, 5125, 5150, 5151, 5154, 5190, 5201, 5222, 5223, 5228, 5242, 5243, 5246, 5247, 5269, 5280, 5281, 5298, 5310, 5349, 5351,
5353, 5355, 5357, 5358, 5394, 5402, 5405, 5412, 5413, 5417, 5421, 5432, 5433, 5445, 5480, 5481, 5495, 5498, 5499, 5500, 5501, 5517, 5550, 5554, 5555, 5556, 5568, 5601, 5631, 5632,
5656, 5666, 5667, 5670, 5672, 5678, 5683, 5701, 5718, 5719, 5722, 5723, 5724, 5741, 5742, 5800, 5900, 5931, 5938, 5984, 5985, 5986, 5988, 6000, 6001, 6002, 6003, 6004, 6005, 6006,
6007, 6008, 6009, 6010, 6011, 6012, 6013, 6014, 6015, 6016, 6017, 6018, 6019, 6020, 6021, 6022, 6023, 6024, 6025, 6026, 6027, 6028, 6029, 6030, 6031, 6032, 6033, 6034, 6035, 6036,
6037, 6038, 6039, 6040, 6041, 6042, 6043, 6044, 6045, 6046, 6047, 6048, 6049, 6050, 6051, 6052, 6053, 6054, 6055, 6056, 6057, 6058, 6059, 6060, 6061, 6062, 6063, 6086, 6100, 6101,
6110, 6111, 6112, 6113, 6136, 6159, 6200, 6201, 6225, 6227, 6240, 6244, 6255, 6257, 6260, 6262, 6343, 6346, 6347, 6350, 6379, 6389, 6432, 6436, 6437, 6444, 6445, 6463, 6502, 6513,
6514, 6515, 6543, 6556, 6560, 6566, 6571, 6600, 6601, 6602, 6619, 6622, 6653, 6660, 6665, 6679, 6690, 6697, 6699, 6715, 6771, 6783, 6789, 6869, 6881, 6888, 6889, 6891, 6901, 6902,
6969, 6970, 7000, 7001, 7002, 7005, 7006, 7010, 7022, 7023, 7025, 7047, 7070, 7133, 7144, 7145, 7171, 7262, 7272, 7306, 7307, 7312, 7396, 7400, 7401, 7402, 7471, 7473, 7474, 7478,
7542, 7547, 7575, 7624, 7631, 7634, 7652, 7655, 7656, 7670, 7687, 7707, 7717, 7777, 7831, 7880, 7890, 7915, 7935, 7946, 7990, 8000, 8005, 8006, 8007, 8008, 8009, 8042, 8069, 8070,
8074, 8075, 8080, 8088, 8089, 8090, 8091, 8092, 8111, 8112, 8116, 8118, 8123, 8139, 8140, 8172, 8184, 8194, 8200, 8222, 8243, 8245, 8280, 8281, 8291, 8303, 8332, 8333, 8337, 8384,
8388, 8443, 8444, 8484, 8500, 8530, 8531, 8580, 8629, 8642, 8691, 8767, 8834, 8840, 8880, 8883, 8887, 8888, 8889, 8983, 8997, 8998, 8999, 9000, 9001, 9002, 9006, 9030, 9042, 9043,
9050, 9060, 9080, 9090, 9091, 9092, 9100, 9101, 9102, 9103, 9119, 9150, 9191, 9199, 9200, 9217, 9293, 9300, 9303, 9306, 9309, 9312, 9332, 9333, 9339, 9389, 9418, 9419, 9420, 9421,
9422, 9425, 9443, 9535, 9536, 9600, 9675, 9676, 9695, 9785, 9800, 9875, 9898, 9899, 9981, 9982, 9987, 9993, 9997, 9999, 10000, 10001, 10009, 10010, 10024, 10025, 10042, 10050, 10051,
10080, 10110, 10172, 10200, 10201, 10212, 10308, 10480, 10505, 10514, 10823, 10891, 10933, 11001, 11111, 11112, 11211, 11214, 11215, 11235, 11311, 11371, 11753, 12012, 12013, 12035,
12043, 12046, 12201, 12222, 12223, 12345, 12443, 12489, 12975, 13000, 13008, 13075, 13720, 13721, 13724, 13782, 13783, 13785, 13786, 14550, 14567, 15000, 15345, 15441, 15567, 15672,
16000, 16080, 16200, 16225, 16250, 16261, 16300, 16384, 16385, 16386, 16387, 16393, 16394, 16395, 16396, 16397, 16398, 16399, 16400, 16401, 16402, 16403, 16404, 16405, 16406, 16407,
16408, 16409, 16410, 16411, 16412, 16413, 16414, 16415, 16416, 16417, 16418, 16419, 16420, 16421, 16422, 16423, 16424, 16425, 16426, 16427, 16428, 16429, 16430, 16431, 16432, 16433,
16434, 16435, 16436, 16437, 16438, 16439, 16440, 16441, 16442, 16443, 16444, 16445, 16446, 16447, 16448, 16449, 16450, 16451, 16452, 16453, 16454, 16455, 16456, 16457, 16458, 16459,
16460, 16461, 16462, 16463, 16464, 16465, 16466, 16467, 16468, 16469, 16470, 16471, 16472, 16482, 16567, 17011, 17500, 18091, 18092, 18104, 18200, 18201, 18206, 18300, 18301, 18306,
18333, 18400, 18401, 18505, 18506, 18605, 18606, 19000, 19001, 19132, 19150, 19226, 19294, 19295, 19302, 19812, 19813, 19814, 19999, 20000, 20560, 20595, 20808, 21025, 22000, 22136,
22222, 23073, 23399, 23513, 24441, 24444, 24465, 24554, 24800, 24842, 25565, 25575, 25826, 26000, 26900, 27000, 27016, 27017, 27031, 27036, 27037, 27374, 27500, 27888, 27901, 27950,
27960, 28001, 28015, 28770, 28785, 28852, 28910, 28960, 29000, 29070, 29900, 29920, 30564, 31337, 31416, 31438, 31457, 32137, 32400, 32764, 32887, 32976, 33434, 33848, 34000, 34197,
35357, 37008, 40000, 43110, 43594, 44405, 44818, 47001, 47808, 49151];
// From https://github.com/coverslide/node-alea
const AleaModule = function () {
// importState to sync generator states
Alea.importState = function(i){
var random = new Alea();
random.importState(i);
return random;
};
return Alea;
function Alea() {
return (function(args) {
// Johannes Baagøe <baagoe@baagoe.com>, 2010
var s0 = 0;
var s1 = 0;
var s2 = 0;
var c = 1;
if (args.length === 0) {
args = [+new Date()];
}
var mash = Mash();
s0 = mash(' ');
s1 = mash(' ');
s2 = mash(' ');
for (var i = 0; i < args.length; i++) {
s0 -= mash(args[i]);
if (s0 < 0) {
s0 += 1;
}
s1 -= mash(args[i]);
if (s1 < 0) {
s1 += 1;
}
s2 -= mash(args[i]);
if (s2 < 0) {
s2 += 1;
}
}
mash = null;
var random = function() {
var t = 2091639 * s0 + c * 2.3283064365386963e-10; // 2^-32
s0 = s1;
s1 = s2;
return s2 = t - (c = t | 0);
};
random.uint32 = function() {
return random() * 0x100000000; // 2^32
};
random.fract53 = function() {
return random() +
(random() * 0x200000 | 0) * 1.1102230246251565e-16; // 2^-53
};
random.version = 'Alea 0.9';
random.args = args;
// my own additions to sync state between two generators
random.exportState = function(){
return [s0, s1, s2, c];
};
random.importState = function(i){
s0 = +i[0] || 0;
s1 = +i[1] || 0;
s2 = +i[2] || 0;
c = +i[3] || 0;
};
return random;
} (Array.prototype.slice.call(arguments)));
}
function Mash() {
var n = 0xefc8249d;
var mash = function(data) {
data = data.toString();
for (var i = 0; i < data.length; i++) {
n += data.charCodeAt(i);
var h = 0.02519603282416938 * n;
n = h >>> 0;
h -= n;
h *= n;
n = h >>> 0;
h -= n;
n += h * 0x100000000; // 2^32
}
return (n >>> 0) * 2.3283064365386963e-10; // 2^-32
};
mash.version = 'Mash 0.9';
return mash;
}
}
const Alea = AleaModule()
function randomClipperPort(state, env) {
const seed = env === 'prod' ? 1867 : 2001;
const startPorts = {
prod: 41184,
dev: 27583,
};
const minPort = 1024
const maxPort = 49151
const startPort = env === 'prod' ? startPorts.prod : startPorts.dev;
let prng = null;
if (!state) {
prng = new Alea(seed)
state = { prng: prng }
state = { offset: 0 };
} else {
prng = state.prng;
state.offset++;
}
const randomPort = () => {
return minPort + Math.floor(prng() * ((maxPort + 1) - minPort));
}
let port = null;
for (let i = 0; i < maxPort; i++) {
port = randomPort();
if (reservedPorts.indexOf(port) < 0) break;
}
if (!port) throw new Error('Cannot find a non-reserved port');
state.port = port;
state.port = startPort + state.offset;
return state;
}

View File

@ -248,28 +248,27 @@
</li>
</ul>
</div>
<h1 id="joplin-web-clipper">Joplin Web Clipper</h1>
<p>The Web Clipper is a browser extension that allows you to save web pages and screenshots from your browser. To start using it, open the Joplin desktop application, go to the <strong>Web Clipper Options</strong> and follow the instructions.</p>
<p><img src="https://joplin.cozic.net/images/WebExtensionScreenshot.png" alt=""></p>
<h1 id="troubleshooting-the-web-clipper-service">Troubleshooting the web clipper service</h1>
<p>The web clipper extension and the Joplin application communicates via a service, which is started by the Joplin desktop app.</p>
<p>However certain things can interfer with this service and prevent it from being accessible or from starting. If something does not work, check the following:</p>
<ul>
<li><p>Check that the service is started. You can check this in the Web clipper options in the desktop app.</p>
</li>
<li><p>Check that the port used by the service is not blocked by a firewall. You can find the port number in the Web clipper options in the desktop Joplin application.</p>
</li>
<li><p>Check that no proxy is running on the machine, or make sure that the requests from the web clipper service are filtered and allowed. For example <a href="https://github.com/laurent22/joplin/issues/561#issuecomment-392220191">https://github.com/laurent22/joplin/issues/561#issuecomment-392220191</a></p>
</li>
<li>Check that the service is started. You can check this in the Web clipper options in the desktop app.</li>
<li>Check that the port used by the service is not blocked by a firewall. You can find the port number in the Web clipper options in the desktop Joplin application.</li>
<li>Check that no proxy is running on the machine, or make sure that the requests from the web clipper service are filtered and allowed. For example <a href="https://github.com/laurent22/joplin/issues/561#issuecomment-392220191">https://github.com/laurent22/joplin/issues/561#issuecomment-392220191</a></li>
</ul>
<p>If none of this work, please report it on the <a href="https://discourse.joplin.cozic.net/">forum</a> or <a href="https://github.com/laurent22/joplin/issues">GitHub issue tracker</a></p>
<h1 id="debugging-the-extension">Debugging the extension</h1>
<h2 id="in-chrome">In Chrome</h2>
<p>To provide as much information as possible when reporting an issue, you may provide the log from the various Chrome console.</p>
<p>To do so, first enable developer mode in <a href="chrome://extensions/">chrome://extensions/</a></p>
<h3 id="debugging-the-popup">Debugging the popup</h3>
<p>Right-click on the Joplin extension icon, and select &quot;Inspect popup&quot;.</p>
<h3 id="debugging-the-background-script">Debugging the background script</h3>
<p>In <code>chrome://extensions/</code>, click on &quot;Inspect background script&quot;.</p>
<h3 id="debugging-the-content-script">Debugging the content script</h3>
<p>Press Ctrl+Shift+I to open the console of the current page.</p>
<ul>
<li>Debugging the popup: Right-click on the Joplin extension icon, and select &quot;Inspect popup&quot;.</li>
<li>Debugging the background script: In <code>chrome://extensions/</code>, click on &quot;Inspect background script&quot;.</li>
<li>Debugging the content script: Press Ctrl+Shift+I to open the console of the current page.</li>
</ul>
<h2 id="in-firefox">In Firefox</h2>
<ul>
<li>Open <a href="about:debugging">about:debugging</a> in Firefox.</li>
@ -280,6 +279,84 @@
<p>Also press F12 to open the regular Firefox console (some messages from the Joplin extension can go there too).</p>
<p>Now use the extension as normal and replicate the bug you&#39;re having.</p>
<p>Copy and paste the content of both the debugging window and the Firefox console, and post it to the <a href="https://discourse.joplin.cozic.net/">forum</a>.</p>
<h1 id="using-the-web-clipper-service">Using the Web Clipper service</h1>
<p>The Web Clipper service can be used to create notes from any other application. It exposes a <a href="https://en.wikipedia.org/wiki/Representational_state_transfer">REST API</a> with a number of methods to list folders and to create notes or attach images.</p>
<p>In order to use it, you&#39;ll first need to find on which port the service is running. To do so, open the Web Clipper Option in Joplin and if the service is running it should tell you on which port. Normally it runs on port <strong>41184</strong>. If you want to find it programmatically, you may follow this kind of algorithm:</p>
<pre><code class="lang-javascript">let port = null;
for (let portToTest = 41184; portToTest &lt;= 41194; portToTest++) {
const result = pingPort(portToTest); // Call GET /ping
if (result == &#39;JoplinClipperServer&#39;) {
port = portToTest; // Found the port
break;
}
}
</code></pre>
<p>start from 41184, then ping it (using the /ping method below)</p>
<p>The following methods are available:</p>
<h3 id="get-ping">GET /ping</h3>
<p>Tells whether the service is active or not. It should return &quot;JoplinClipperServer&quot; if it works.</p>
<p>Example: <code>curl http://127.0.0.1:41184/ping</code></p>
<h3 id="get-folders">GET /folders</h3>
<p>Returns the list of notebooks (called &quot;folders&quot; internally) as a tree. The sub-notebooks of a notebook, if any, are under the <code>children</code> key.</p>
<p>Example: <code>curl http://127.0.0.1:41184/folders</code></p>
<h3 id="post-notes">POST /notes</h3>
<p>Creates a new note. You can either specify the note body as Markdown by setting the <code>body</code> parameter, or in HTML by setting the <code>body_html</code>. All parameter are optional.</p>
<p>Parameters:</p>
<table>
<thead>
<tr>
<th>Key</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr>
<td>title</td>
<td>Note title</td>
</tr>
<tr>
<td>body</td>
<td>Note body, in Markdown</td>
</tr>
<tr>
<td>body_html</td>
<td>Note body, in HTML format</td>
</tr>
<tr>
<td>source_url</td>
<td>The URL the note comes from</td>
</tr>
<tr>
<td>parent_id</td>
<td>The notebook (ID) to move the note to</td>
</tr>
<tr>
<td>base_url</td>
<td>If <code>body_html</code> is provided and contains relative URLs, provide the <code>base_url</code> parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the &#39;?&#39;). For example if the original page was <code>https://stackoverflow.com/search?q=%5Bjava%5D+test</code>, the base URL is <code>https://stackoverflow.com/search</code>.</td>
</tr>
<tr>
<td>image_data_url</td>
<td>An image to attach to the note, in <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs">Data URL</a> format.</td>
</tr>
<tr>
<td>crop_rect</td>
<td>If an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format <code>{ x: x, y: y, width: width, height: height }</code></td>
</tr>
</tbody>
</table>
<p>Examples:</p>
<ul>
<li>Create a note from some Markdown text</li>
</ul>
<p><code>curl --data &#39;{ &quot;title&quot;: &quot;My note&quot;, &quot;body&quot;: &quot;Some note in **Markdown**&quot;}&#39; http://127.0.0.1:41184/notes</code></p>
<ul>
<li>Create a note from some HTML</li>
</ul>
<p><code>curl --data &#39;{ &quot;title&quot;: &quot;My note&quot;, &quot;body_html&quot;: &quot;Some note in &lt;b&gt;HTML&lt;/b&gt;&quot;}&#39; http://127.0.0.1:41184/notes</code></p>
<ul>
<li>Create a note and attach an image to it:</li>
</ul>
<p><code>curl --data &#39;{ &quot;title&quot;: &quot;Image test&quot;, &quot;body&quot;: &quot;Here is Joplin icon:&quot;, &quot;image_data_url&quot;: &quot;data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUeNoAyAA3/wFwtO3K6gUB/vz2+Prw9fj/+/r+/wBZKAAExOgF4/MC9ff+MRH6Ui4E+/0Bqc/zutj6AgT+/Pz7+vv7++nu82c4DlMqCvLs8goA/gL8/fz09fb59vXa6vzZ6vjT5fbn6voD/fwC8vX4UiT9Zi//APHyAP8ACgUBAPv5APz7BPj2+DIaC2o3E+3o6ywaC5fT6gD6/QD9/QEVf9kD+/dcLQgJA/7v8vqfwOf18wA1IAIEVycAyt//v9XvAPv7APz8LhoIAPz9Ri4OAgwARgx4W/6fVeEAAAAASUVORK5CYII=&quot;}&#39; http://127.0.0.1:41184/notes</code></p>
<script>
function stickyHeader() {

Binary file not shown.

After

Width:  |  Height:  |  Size: 387 KiB

View File

@ -1,3 +1,9 @@
# Joplin Web Clipper
The Web Clipper is a browser extension that allows you to save web pages and screenshots from your browser. To start using it, open the Joplin desktop application, go to the **Web Clipper Options** and follow the instructions.
![](https://joplin.cozic.net/images/WebExtensionScreenshot.png)
# Troubleshooting the web clipper service
The web clipper extension and the Joplin application communicates via a service, which is started by the Joplin desktop app.
@ -5,9 +11,7 @@ The web clipper extension and the Joplin application communicates via a service,
However certain things can interfer with this service and prevent it from being accessible or from starting. If something does not work, check the following:
- Check that the service is started. You can check this in the Web clipper options in the desktop app.
- Check that the port used by the service is not blocked by a firewall. You can find the port number in the Web clipper options in the desktop Joplin application.
- Check that no proxy is running on the machine, or make sure that the requests from the web clipper service are filtered and allowed. For example https://github.com/laurent22/joplin/issues/561#issuecomment-392220191
If none of this work, please report it on the [forum](https://discourse.joplin.cozic.net/) or [GitHub issue tracker](https://github.com/laurent22/joplin/issues)
@ -20,17 +24,9 @@ To provide as much information as possible when reporting an issue, you may prov
To do so, first enable developer mode in [chrome://extensions/](chrome://extensions/)
### Debugging the popup
Right-click on the Joplin extension icon, and select "Inspect popup".
### Debugging the background script
In `chrome://extensions/`, click on "Inspect background script".
### Debugging the content script
Press Ctrl+Shift+I to open the console of the current page.
- Debugging the popup: Right-click on the Joplin extension icon, and select "Inspect popup".
- Debugging the background script: In `chrome://extensions/`, click on "Inspect background script".
- Debugging the content script: Press Ctrl+Shift+I to open the console of the current page.
## In Firefox
@ -43,4 +39,68 @@ Also press F12 to open the regular Firefox console (some messages from the Jopli
Now use the extension as normal and replicate the bug you're having.
Copy and paste the content of both the debugging window and the Firefox console, and post it to the [forum](https://discourse.joplin.cozic.net/).
Copy and paste the content of both the debugging window and the Firefox console, and post it to the [forum](https://discourse.joplin.cozic.net/).
# Using the Web Clipper service
The Web Clipper service can be used to create notes from any other application. It exposes a [REST API](https://en.wikipedia.org/wiki/Representational_state_transfer) with a number of methods to list folders and to create notes or attach images.
In order to use it, you'll first need to find on which port the service is running. To do so, open the Web Clipper Option in Joplin and if the service is running it should tell you on which port. Normally it runs on port **41184**. If you want to find it programmatically, you may follow this kind of algorithm:
```javascript
let port = null;
for (let portToTest = 41184; portToTest <= 41194; portToTest++) {
const result = pingPort(portToTest); // Call GET /ping
if (result == 'JoplinClipperServer') {
port = portToTest; // Found the port
break;
}
}
```
start from 41184, then ping it (using the /ping method below)
The following methods are available:
### GET /ping
Tells whether the service is active or not. It should return "JoplinClipperServer" if it works.
Example: `curl http://127.0.0.1:41184/ping`
### GET /folders
Returns the list of notebooks (called "folders" internally) as a tree. The sub-notebooks of a notebook, if any, are under the `children` key.
Example: `curl http://127.0.0.1:41184/folders`
### POST /notes
Creates a new note. You can either specify the note body as Markdown by setting the `body` parameter, or in HTML by setting the `body_html`. All parameter are optional.
Parameters:
Key | Description
---|---
title | Note title
body | Note body, in Markdown
body_html | Note body, in HTML format
source_url | The URL the note comes from
parent_id | The notebook (ID) to move the note to
base_url | If `body_html` is provided and contains relative URLs, provide the `base_url` parameter too so that all the URLs can be converted to absolute ones. The base URL is basically where the HTML was fetched from, minus the query (everything after the '?'). For example if the original page was `https://stackoverflow.com/search?q=%5Bjava%5D+test`, the base URL is `https://stackoverflow.com/search`.
image_data_url | An image to attach to the note, in [Data URL](https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs) format.
crop_rect | If an image is provided, you can also specify an optional rectangle that will be used to crop the image. In format `{ x: x, y: y, width: width, height: height }`
Examples:
* Create a note from some Markdown text
`curl --data '{ "title": "My note", "body": "Some note in **Markdown**"}' http://127.0.0.1:41184/notes`
* Create a note from some HTML
`curl --data '{ "title": "My note", "body_html": "Some note in <b>HTML</b>"}' http://127.0.0.1:41184/notes`
* Create a note and attach an image to it:
`curl --data '{ "title": "Image test", "body": "Here is Joplin icon:", "image_data_url": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAIAAABLbSncAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAANZJREFUeNoAyAA3/wFwtO3K6gUB/vz2+Prw9fj/+/r+/wBZKAAExOgF4/MC9ff+MRH6Ui4E+/0Bqc/zutj6AgT+/Pz7+vv7++nu82c4DlMqCvLs8goA/gL8/fz09fb59vXa6vzZ6vjT5fbn6voD/fwC8vX4UiT9Zi//APHyAP8ACgUBAPv5APz7BPj2+DIaC2o3E+3o6ywaC5fT6gD6/QD9/QEVf9kD+/dcLQgJA/7v8vqfwOf18wA1IAIEVycAyt//v9XvAPv7APz8LhoIAPz9Ri4OAgwARgx4W/6fVeEAAAAASUVORK5CYII="}' http://127.0.0.1:41184/notes`