為了改善您的使用體驗,本網站正在進行維護,部分功能暫時無法使用。若本站的文件無法解決您的問題,想要向社群發問的話,請到 Twitter 上的 @FirefoxSupport 或 Reddit 上的 /r/firefox 發問,我們的社群成員將很快會回覆您的疑問。

搜尋 Mozilla 技術支援網站

防止技術支援詐騙。我們絕對不會要求您撥打電話或發送簡訊,或是提供個人資訊。請用「回報濫用」功能回報可疑的行為。

了解更多

Sessions API not working/recognized in Browser Toolbox?

  • 6 回覆
  • 1 有這個問題
  • 1 次檢視
  • 最近回覆由 TyDraniu

more options

I'm trying to develop a simple addon using the Sessions API, so I wanted to play around a bit with the JS in the Browser Toolbox first. I have set devtools.chrome.enabled to true and pressed Ctrl+Shift+J to open the browser console. I'm able to run some JS (example: console.log("Hello world!") works as expected), but when I try to run something like sessions.getRecentlyClosed(), I get the following error message:

 Uncaught ReferenceError: sessions is not defined
    <anonymous> debugger eval code:1
    getEvalResult resource://devtools/server/actors/webconsole/eval-with-debugger.js:243
    evalWithDebugger resource://devtools/server/actors/webconsole/eval-with-debugger.js:167
    evaluateJS resource://devtools/server/actors/webconsole.js:1119
    evaluateJSAsync resource://devtools/server/actors/webconsole.js:1011
    makeInfallible resource://devtools/shared/ThreadSafeDevToolsUtils.js:103


I tried browser.sessions.getRecentlyClosed() with the same error message about "browser.sessions" not being defined. Anyone know why this is happening and how to fix it, or how to correctly import the Sessions API if that's what's needed?

Thanks!

I'm trying to develop a simple addon using the Sessions API, so I wanted to play around a bit with the JS in the Browser Toolbox first. I have set <b>devtools.chrome.enabled</b> to true and pressed <b>Ctrl+Shift+J</b> to open the browser console. I'm able to run some JS (example: <b>console.log("Hello world!")</b> works as expected), but when I try to run something like <b>sessions.getRecentlyClosed()</b>, I get the following error message: <pre> Uncaught ReferenceError: sessions is not defined <anonymous> debugger eval code:1 getEvalResult resource://devtools/server/actors/webconsole/eval-with-debugger.js:243 evalWithDebugger resource://devtools/server/actors/webconsole/eval-with-debugger.js:167 evaluateJS resource://devtools/server/actors/webconsole.js:1119 evaluateJSAsync resource://devtools/server/actors/webconsole.js:1011 makeInfallible resource://devtools/shared/ThreadSafeDevToolsUtils.js:103 </pre> I tried <b>browser.sessions.getRecentlyClosed()</b> with the same error message about "browser.sessions" not being defined. Anyone know why this is happening and how to fix it, or how to correctly import the Sessions API if that's what's needed? Thanks!

由 fiffox 於 修改

所有回覆 (6)

more options

Hi, for debugging addons you must use the Remote Debugging option, or about:debugging#/runtime/this-firefox

more options

TyDraniu said

Hi, for debugging addons you must use the Remote Debugging option, or about:debugging#/runtime/this-firefox

Hi TyDraniu, sorry for any confusion, but this question is about running javascript in the Browser Console, not debugging an addon. I'll edit the question to make it more clear.

more options

This Session API is available only for webextensions, if i'm not mistaken. You can't just run it within a web console.

more options
more options

TyDraniu said

This Session API is available only for webextensions, if i'm not mistaken. You can't just run it within a web console.

Ah, thanks, I was afraid of that. And I suppose there's no way to import webextension APIs into the console? It sure would be nice to see the output to certain code in real time (especially since the examples in the documentation were a little sparse).

more options

I was using web-ext (https://extensionworkshop.com/documentation/develop/getting-started-with-web-ext/ ) and a console under about:debugging. There is a separate console with output from a browser plus extensions.