doc.location is null error with current translator template

I updated to Zotero 6 recently and the translator template changed accordingly.

With the new code templates I always get the error "doc.location is null" when multiple items are expected to be detected. Single items are working as always.

I created a Test-Multiple translator, where I used the templates for "web translator" and "Embedded Metadata" and adapted the CSS selectors according to the translator "Der Freitag".

17:37:33 TranslatorTester: Running 1 test for Test-Multiple
17:37:33 TranslatorTester: Running Test-Multiple Test 1
17:37:34 TranslatorTester: Translating https://www.freitag.de/@@search?SearchableText=test
17:37:34 Translation using Test-Multiple failed:
TypeError: doc.location is null

Zotero.Translate.Web.prototype.setDocument@chrome://zotero/content/xpcom/translate/src/translation/translate.js:2002:2
loadTranslator/safeTranslator.setDocument@chrome://zotero/content/xpcom/translate/src/translation/translate.js:322:13
scrape@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:92:2
doWeb/</<@chrome://zotero/content/xpcom/translation/translate_firefox.js line 425 > eval:79:51

url => https://www.freitag.de/@@search?SearchableText=test
downloadAssociatedFiles => true
automaticSnapshots => true
17:37:34 TranslatorTester: Test-Multiple Test 1: failed (Translation failed: TypeError: doc.location is null)
  • The code that differs from the code templates:



    let articleDataTagSelector = 'script.qa-structured-data[type="application/ld+json"]';

    async function detectWeb(doc, url) {
    if (doc.querySelector(articleDataTagSelector)) {
    let type = JSON.parse(text(doc, articleDataTagSelector))['@type'];
    if (type == 'NewsArticle'
    || (Array.isArray(type) && type.includes('NewsArticle'))
    ) {
    return "newspaperArticle";
    }
    }
    else if (getSearchResults(doc, true)) {
    return "multiple";
    }
    return false;
    }

    function getSearchResults(doc, checkOnly) {
    var items = {};
    var found = false;
    // TODO: adjust the CSS selector
    var rows = doc.querySelectorAll('.o-search-results__container .c-article-card a.js-article-card-url');
    for (let row of rows) {
    // TODO: check and maybe adjust
    let href = row.href;
    // TODO: check and maybe adjust
    let title = ZU.trimInternal(row.textContent);
    if (!href || !title) continue;
    if (checkOnly) return true;
    found = true;
    items[href] = title;
    }
    return found ? items : false;
    }
  • The tests code:


    [
    {
    "type": "web",
    "url": "https://www.freitag.de/@@search?SearchableText=test",
    "items": "multiple"
    },
    {
    "type": "web",
    "url": "https://www.freitag.de/autoren/der-freitag/201evolksverdummung-ist-nicht-links201c",
    "items": [
    {
    "itemType": "newspaperArticle",
    "title": "Im Gespräch - „Volksverdummung ist nicht links“",
    "creators": [],
    "abstractNote": "Sigmar Gabriel attackiert im Freitag-Interview den griechischen Linken Alexis Tsipras. Die Piratenpartei hält der SPD-Chef für ein Zeitgeist-Phänomen",
    "language": "de",
    "libraryCatalog": "www.freitag.de",
    "section": "News",
    "url": "https://www.freitag.de/autoren/der-freitag/201evolksverdummung-ist-nicht-links201c",
    "attachments": [
    {
    "title": "Snapshot",
    "mimeType": "text/html"
    }
    ],
    "tags": [
    {
    "tag": "Die Wochenzeitung"
    },
    {
    "tag": "Freitag"
    },
    {
    "tag": "der Freitag"
    },
    {
    "tag": "inland"
    },
    {
    "tag": "piraten"
    },
    {
    "tag": "sigmar gabriel"
    },
    {
    "tag": "spd"
    }
    ],
    "notes": [],
    "seeAlso": []
    }
    ]
    }
    ]
  • Sorry, the fix for this hasn't made it into the connectors yet. For now, you can use the old template or just test in Scaffold. (The issue is with requestDocument not correctly adding a location property to the returned document.)
  • Thanks for the quick reply.

    The error occurred while testing in Scaffold, too (the error log in my first post here). Scaffold is the Translator editor or am I mistaken?
  • It is. I’ll take a look.
  • OK, thanks for reporting! Just pushed a fix which will be available in the next beta (and forthcoming stable release).
  • Fixed in the Connector beta. A client beta with the fix should be out soon.
Sign In or Register to comment.