If you’re having trouble with something, please just report it in a new thread so we can investigate. Don’t hijack an unrelated thread with a question about downgrading.
What’s an example URL where you’re having trouble?
The new version plugin report: ``` [JavaScript Error: "Error: Service worker (re)started at 2024-06-05 15:28:08 at Object.initGlobal (chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/zotero.js:182:20)"]
[JavaScript Error: "TypeError: Cannot read properties of null (reading 'children') at scrape (bzsb.info:83:59) at doWeb (bzsb.info:72:9) at Zotero.Translate.Web.rest (chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/translate/translation/translate.js:1346:49) at chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/translate/translation/translate.js:1331:39" {file: "[object Object]"}] ```
The Identical code , I can run code in the old version connector and Browser console, but it doesn't work in the latest version connector ``` var eleId = ''; var xhr = new XMLHttpRequest(); xhr.open("POST", "searchStandard.do?action=searchPDFLanguage", false); xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xhr.onreadystatechange = function() { if (xhr.readyState === 4 && xhr.status === 200) { eleId = JSON.parse(xhr.responseText)[0].id; } }; var data = "docId=" + '594122' + "&" + "originalId=" + 'da17dc0912f1a5ae65b6ed991ffa80ac' + "&" + "a100=" + 'NB/T 47014-2011' xhr.send(data); ``` URL: https://www.bzsb.info/searchStandard.do?action=searchStandardDetail https://s3.amazonaws.com/zotero.org/images/forums/u11764939/ebp4hsy8l8g724mecifv.png
Google Chrome is phasing out Manifest V2 extensions, so even if you could theoretically install the old version, it will stop working soon. We have updated the Zotero Connector for Manifest V3, which required some technical changes and there may be some bugs.
You will have to explain in full detail what the issue is. The URL you have posted does not load for me in europe. Did saving from this website work before with the default connector, or did you need to make some customizations before it worked? What kind of customizations were you making, and how?
This is not the way to get help here — you're wasting your time and ours. If you're having trouble writing in English, please write in your native language.
So far you haven't even asked a question about Zotero — you've just posted some JavaScript code from your browser console that doesn't have anything to do with Zotero.
If you're asking about a custom Zotero translator, post a link to the full code and a Debug ID from the Zotero Connector for reloading the page and trying to save.
I just tested and located my code error, and I couldn't reply to your message in a timely manner. I'm very sorry. I have submitted the report, ID: 2135884265. my translator script is below: ``` { "translatorID": "2831874d-4574-45e4-bc6e-e47048eb6857", "label": "bzsb.info", "creator": "yailimumu@gmail.com>", "target": "https?://www\\.bzsb\\.info", "minVersion": "3.0", "maxVersion": "", "priority": 100, "inRepository": true, "translatorType": 4, "browserSupport": "gcsibv", "lastUpdated": "2024-01-03 07:22:12" }
function detectWeb(doc, url) { if (url.includes('/searchStandard.do')) { return 'standard'; } else if (getSearchResults(doc, true)) { return 'multiple'; } return false; }
function getSearchResults(doc, checkOnly) { var items = {}; var found = false; var rows = doc.querySelectorAll('li > a[href*="/online/"]:nth-child(2), .titleft > a[href*="/online/"]:nth-child(2)'); for (let row of rows) { let href = row.href; let title = ZU.trimInternal(row.textContent); if (!href || !title) continue; if (checkOnly) return true; found = true; items[href] = title; } return found ? items : false; }
async function doWeb(doc, url) { if (detectWeb(doc, url) == 'multiple') { let items = await Zotero.selectItems(getSearchResults(doc, false)); if (!items) return; for (let url of Object.keys(items)) { await scrape(await requestDocument(url)); } } else { await scrape(doc, url); } }
async function scrape(doc, url = doc.location.href) { var newItem = new Z.Item('standard'); newItem.extra = ''; const labels = new Labels(doc, '[class="detailBox category_param_list"] > dd'); Z.debug(labels.innerData.map(arr => [arr[0], ZU.trimInternal(arr[1].innerText)]));
@yaolimumu: But this is totally wrong — you can't use XHR directly in a Zotero translator.
You should use the Translator Editor in Zotero to create and test your translator, and you should follow the translator documentation and other translators to write your code.
Yes, we know what XHR is. It's never been supported in Zotero translators. Look for await request in other translators for examples of how to make HTTP requests.
The code always work fine until the updated version connector was released; so why was it possible to use XHR components until the updated version connector was released?
Because you were taking advantage of a fluke of one particular environment where translators ran and ignoring all documentation and all examples of how to make HTTP requests. You didn't write an actual Zotero translator — you wrote some invalid code that happened to run. With the MV3 update, invalid code like that will no longer work.
We're not going to spend more time on this. Again, you can look at existing translators for examples of how to do this properly.
Your code doesn't have anything to do with MV3. The point is that you need to write an actual Zotero translator, looking at our documentation and examples from official Zotero translators. You just wrote some random JavaScript and expected it to work in a translator.
What’s an example URL where you’re having trouble?
```
[JavaScript Error: "Error: Service worker (re)started at 2024-06-05 15:28:08
at Object.initGlobal (chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/zotero.js:182:20)"]
[JavaScript Error: "TypeError: Cannot read properties of null (reading 'children')
at scrape (bzsb.info:83:59)
at doWeb (bzsb.info:72:9)
at Zotero.Translate.Web.rest (chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/translate/translation/translate.js:1346:49)
at chrome-extension://ekhagklcjbdpajgpjgmbionohlpdbjgc/translate/translation/translate.js:1331:39" {file: "[object Object]"}]
```
but it doesn't work in the latest version connector
```
var eleId = '';
var xhr = new XMLHttpRequest();
xhr.open("POST", "searchStandard.do?action=searchPDFLanguage", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
eleId = JSON.parse(xhr.responseText)[0].id;
}
};
var data = "docId=" + '594122' + "&" + "originalId=" + 'da17dc0912f1a5ae65b6ed991ffa80ac' + "&" + "a100=" + 'NB/T 47014-2011'
xhr.send(data);
```
URL: https://www.bzsb.info/searchStandard.do?action=searchStandardDetail
https://s3.amazonaws.com/zotero.org/images/forums/u11764939/ebp4hsy8l8g724mecifv.png
You will have to explain in full detail what the issue is. The URL you have posted does not load for me in europe. Did saving from this website work before with the default connector, or did you need to make some customizations before it worked? What kind of customizations were you making, and how?
So far you haven't even asked a question about Zotero — you've just posted some JavaScript code from your browser console that doesn't have anything to do with Zotero.
If you're asking about a custom Zotero translator, post a link to the full code and a Debug ID from the Zotero Connector for reloading the page and trying to save.
I have submitted the report, ID: 2135884265.
my translator script is below:
```
{
"translatorID": "2831874d-4574-45e4-bc6e-e47048eb6857",
"label": "bzsb.info",
"creator": "yailimumu@gmail.com>",
"target": "https?://www\\.bzsb\\.info",
"minVersion": "3.0",
"maxVersion": "",
"priority": 100,
"inRepository": true,
"translatorType": 4,
"browserSupport": "gcsibv",
"lastUpdated": "2024-01-03 07:22:12"
}
function detectWeb(doc, url) {
if (url.includes('/searchStandard.do')) {
return 'standard';
}
else if (getSearchResults(doc, true)) {
return 'multiple';
}
return false;
}
function getSearchResults(doc, checkOnly) {
var items = {};
var found = false;
var rows = doc.querySelectorAll('li > a[href*="/online/"]:nth-child(2), .titleft > a[href*="/online/"]:nth-child(2)');
for (let row of rows) {
let href = row.href;
let title = ZU.trimInternal(row.textContent);
if (!href || !title) continue;
if (checkOnly) return true;
found = true;
items[href] = title;
}
return found ? items : false;
}
async function doWeb(doc, url) {
if (detectWeb(doc, url) == 'multiple') {
let items = await Zotero.selectItems(getSearchResults(doc, false));
if (!items) return;
for (let url of Object.keys(items)) {
await scrape(await requestDocument(url));
}
}
else {
await scrape(doc, url);
}
}
async function scrape(doc, url = doc.location.href) {
var newItem = new Z.Item('standard');
newItem.extra = '';
const labels = new Labels(doc, '[class="detailBox category_param_list"] > dd');
Z.debug(labels.innerData.map(arr => [arr[0], ZU.trimInternal(arr[1].innerText)]));
//let temp = '';
let temp = doc.querySelector('[class="edit_part_title"]').children[1].textContent;
//newItem.title = document.title;
try { newItem.abstractNote = doc.querySelector('[class="span8"]').children[0].children[0].children[1].children[0].innerText; } catch(error) {};
try { newItem.type = doc.querySelector('[class="detailtopBox nowbgc"]').children[2].children[0].children[1].children[1].innerText; } catch(error) {};
newItem.number = doc.querySelector('[class="edit_part_title"]').firstChild.textContent.replace(/\t|\n/g, '');
let docId = doc.querySelector('[class="edit_part_title"]').children[2].id.replace(/msgFeedback_|_a.*/g, '');
newItem.shortTitle = newItem.number.replace(/\s|\/T|\/Z|-\d{4}$/g, '');
newItem.title = newItem.number + ' ' + temp;
newItem.status = {
现行 : 'Implemented',
废弃 : "Deprecated",
未实施 : "Imposed",
调整 : "Adjusting",
部分实施 : "Part Implemented"
} [ doc.querySelector('[class="btn-success mark"]')? doc.querySelector('[class="btn-success mark"]').firstChild.nodeValue : "未实施" ];
newItem.date = labels.getWith('发布日期');
//newItem.url = url;
newItem.numPages = labels.getWith('全文页数');
newItem.language = {
中文 : 'zh-CN',
de : 'De',
en : 'En'
}[labels.getWith('全文语种')];
let lan_A300 = {
中文 : '中文',
de : '德语',
en : '英语'
}[labels.getWith('全文语种')];
newItem.libraryCatalog = '中国河北标准馆';
newItem.extra += addExtra('original-title', labels.getWith('英文名称'));
newItem.extra += addExtra('applyDate', labels.getWith('实施日期'));
newItem.extra += addExtra('ICS', labels.getWith('标准ICS号'));
newItem.extra += addExtra('CCS', labels.getWith('中标分类号'));
newItem.extra += addExtra('draftsman', labels.getWith('起草人'));
newItem.extra += addExtra('drafting-committee', labels.getWith('起草单位'));
newItem.committee = labels.getWith('起草单位');
newItem.publisher = labels.getWith("发布机构");
newItem.extra += addExtra('presenter', labels.getWith('提出单位'));
newItem.extra += addExtra('substitute-for', labels.getWith('替代以下标准'));
newItem.extra += addExtra('substitute-by', labels.getWith('被以下标准替代'));
newItem.extra += addExtra('reference', labels.getWith('引用标准'));
newItem.extra += addExtra('adopted', labels.getWith('采用标准'));
newItem.creators.push({
firstName: '',
lastName: labels.getWith('归口单位').replace(/\(.*\)$/, ''),
creatorType: 'author',
fieldMode: 1
});
var eleId = '';
var xhr = new XMLHttpRequest();
xhr.open("POST", "searchStandard.do?action=searchPDFLanguage", false);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function() {
if (xhr.readyState === 4 && xhr.status === 200) {
eleId = JSON.parse(xhr.responseText)[0].id;
}
};
var data = "docId=" + docId + "&" + "originalId=" + docId + "&" + "a100=" + newItem.number;
xhr.send(data);
if (eleId) {
var previewUrl = "https://www.bzsb.info/standardView.jsp?docId=&pageNum=14&fileName=&originalId=" + docId +
"&a100=" + newItem.number + "&A300=" + lan_A300 + "&eleId=" + eleId;
newItem.url = previewUrl;
var webgetUrl="https://www.bzsb.info/searchStandard.do?action=getPdf";
//Z.debug(pdfurl);
var Http = new XMLHttpRequest();
Http.open("GET", previewUrl);
Http.onreadystatechange = function() {
if (Http.readyState === 4 && Http.status === 200) {
// 在请求成功后的逻辑处理
var webgeturl = webgetUrl + doc.cookie;
var xhr11 = new XMLHttpRequest();
xhr11.open("GET", webgeturl, true);
xhr11.onreadystatechange = function() {
if (xhr11.readyState === 4 && xhr11.status === 200) {
// 在请求成功后的逻辑处理
}};
xhr11.send();
}
};
Http.send();
var pdfurl = "https://www.bzsb.info/searchStandard.do?action=getPdf";
newItem.attachments.push( {
title: "[Standard] Full Text PDF",
mimeType: "application/pdf",
url: pdfurl
});
};
newItem.complete();
}
class Labels {
constructor(doc, selector) {
this.innerData = [];
Array.from(doc.querySelectorAll(selector))
.filter(element => element.firstElementChild)
.filter(element => !element.querySelector(selector))
.filter(element => !/^\s*$/.test(element.textContent))
.forEach((element) => {
let elementCopy = element.cloneNode(true);
try { elementCopy.removeChild(elementCopy.querySelector('.edit_param')); } catch(error) {};
let key = elementCopy.removeChild(elementCopy.firstElementChild).innerText.replace(/\s/g, '');
//let key = elementCopy.removeChild(elementCopy.querySelector('.edit_param'));
this.innerData.push([key, elementCopy]);
});
}
getWith(label, element = false) {
if (Array.isArray(label)) {
let result = label
.map(aLabel => this.getWith(aLabel, element));
result = element
? result.find(element => element.childNodes.length)
: result.find(element => element);
return result
? result
: element
? document.createElement('div')
: '';
}
let pattern = new RegExp(label, 'i');
let keyValPair = this.innerData.find(element => pattern.test(element[0]));
if (element) return keyValPair ? keyValPair[1] : document.createElement('div');
return keyValPair
? ZU.trimInternal(keyValPair[1].innerText)
: '';
}
}
function addExtra(key, value) {
return value
? `${key}: ${value}\n`
: '';
}/** BEGIN TEST CASES **/
```
You should use the Translator Editor in Zotero to create and test your translator, and you should follow the translator documentation and other translators to write your code.
await request
in other translators for examples of how to make HTTP requests.We're not going to spend more time on this. Again, you can look at existing translators for examples of how to do this properly.