【发布时间】:2013-10-02 06:32:50
【问题描述】:
据我所知,个人数据始终保存在配置文件路径中,可以在 chrome://version 中找到。
我在我的 Chrome 开发工具中添加了许多 sn-ps,并且想要备份它们。
但是我在这个路径下找不到保存sn-ps数据的文件。
有人知道吗?请告诉我 。非常感谢!
【问题讨论】:
标签: google-chrome google-chrome-devtools code-snippets
据我所知,个人数据始终保存在配置文件路径中,可以在 chrome://version 中找到。
我在我的 Chrome 开发工具中添加了许多 sn-ps,并且想要备份它们。
但是我在这个路径下找不到保存sn-ps数据的文件。
有人知道吗?请告诉我 。非常感谢!
【问题讨论】:
标签: google-chrome google-chrome-devtools code-snippets
从 Chrome 47(或更高版本)开始,sn-ps 不再可通过 localStorage 使用。此外,natchiketa 的答案取决于 localStorage 并且不再起作用。
以下是当前的技术:
InspectorFrontendHost.getPreferences(_ => console.log(JSON.parse(_.scriptSnippets)))
InspectorFrontendHost.setPreference("scriptSnippets", JSON.stringify(yourSnippets))
此技术摘自讨论此更改的github thread。
【讨论】:
在我的ubuntu18,chromium sn-ps 保存在:
~/.config/chromium/Default/Preferences
作为单行 json 文件。
以上和Bookmarks是我平时备份的文件。
如果您解析该 Preferences json 文件,您会在以下 json 路径中找到 sn-ps:
ROOT.devtools.preferences.scriptSnippets
该属性的值需要再次解析为 json。 然后你会为你的所有 sn-ps 获得一个 {name,content} 数组。
注意:我在下面的命令中使用jq-1.6
备份所有sn-pes到一个json文件:
jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson' > /tmp/backup.json
将所有 sn-ps 备份到 单独的 .js 文件
# Tested with jq-1.6
# The script converts json entries into lines of format
# `filename[TAB]content-in-base64` and then
# for each line creates the corresponding file
# with the content decoded.
# Better be in a safe directory!!
mkdir /tmp/snippets-backup
cd /tmp/snippets-backup
jq .devtools.preferences.scriptSnippets ~/.config/chromium/Default/Preferences \
| jq '. | fromjson | .[]| [ .name, @base64 "\(.content)" ] | @tsv' -r \
| xargs -I{} /bin/bash -c 'file=$(echo "{}"|cut -f1); fileContent=$(echo "{}"|cut -f2); echo "$fileContent" | base64 -d > "${file}.js"'
jq 是一个很棒的命令行工具,用于查询和处理 JSON 文件。你可以从stedolan.github.io/jq/获得它。
【讨论】:
jq 是什么以及从哪里获得它,因为它是第 3 方工具。此外,我的 Preferences 文件根本不包含任何出现的字符串 snippets(我使用的是 Chrome 76.0)。
编辑(2016 年 1 月) 警告:我只能从最近的反对票中假设这不再有效。有机会我会更新的。
[{id: n, name: 'foo.js', content: "The script"}] 的数组
在 OS X 上,假设您安装了一个 sqlite 命令行客户端(我已经安装了一个,但我不记得安装了一个),您会这样找到它:
# 如果你不知道 Chrome Profiles 是什么,你可能会使用 Profile 1,所以: cd ~/Library/Application\ Support/Google/Chrome/Profile\ 1/Local\ Storage
在这个目录中你应该有一个名为chrome-devtools_devtools_0.localstorage的文件,如果有,你应该可以这样做:
sqlite3 chrome-devtools_devtools_0.localstorage
...你应该在 sqlite shell 中,它的开头是这样的:
SQLite version 3.7.13 2012-07-17 17:46:21
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite>
您可以通过.tables 来查看此文件中的表格:
sqlite> .tables
ItemTable
然后您可以这样做以查看该表中的列名:
PRAGMA table_info(ItemTable);
由于 localStorage 只是一个键/值存储,这个表非常简单:
0|key|TEXT|0||0
1|value|BLOB|1||0
看看键名会更有启发性:
select key from ItemTable;
您应该会看到如下内容:
fileSystemMapping
showAdvancedHeapSnapshotProperties
lastDockState
resourcesLargeRows
networkResourceTypeFilters
pauseOnCaughtException
showInheritedComputedStyleProperties
elementsPanelSplitViewState
filterBar-networkPanel-toggled
networkLogColumnsVisibility
networkPanelSplitViewState
sourcesPanelDebuggerSidebarSplitViewState
pauseOnExceptionEnabled
watchExpressions
breakpoints
consoleHistory
domBreakpoints
Inspector.drawerSplitViewState
InspectorView.splitViewState
WebInspector.Drawer.lastSelectedView
currentDockState
editorInDrawerSplitViewState
experiments
inspectorVersion
lastActivePanel
sourcesPanelSplitViewState
sourcesPanelNavigatorSplitViewState
scriptSnippets_lastIdentifier
previouslyViewedFiles
revision-history
revision-history|Script snippet #1|20267.2|1410876616909
scriptSnippets
sn-ps 位于scriptsSnippets。当我开始这样做时,我没有sn-ps,所以我没有看到这个键。在创建我的第一个 sn-p 后,密钥出现了。所以接下来我做了:
select * from ItemTable where key = 'scriptSnippets';
瞧!
scriptSnippets|[{"id":"1","name":"SnipFoo.js","content":"/**\n * @license\n * Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>\n * Build: `lodash modern -o ./dist/lodash.js`\n * Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>\n * Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>\n * Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors\n * Available under MIT license <http://lodash.com/license>\n */\n;(function() {\n\n /** Used as a safe reference for `undefined` in pre ES5 environments */\n var undefined;\n\n /** Used to pool arrays and objects used internally */\n var arrayPool = [],\n objectPool = [];\n\n /** Used to generate unique IDs */\n var idCounter = 0;\n\n /** Used to prefix keys to avoid issues with `__proto__` and properties on `Object.prototype` */\n var keyPrefix = +new Date + '';\n\n /** Used as the size when optimizations are enabled for large arrays */\n var largeArraySize = 75;\n\n /** Used as the max size of the `arrayPool` and `objectPool` */\n var maxPoolSize = 40;\n\n /** Used to detect and test whitespace */\n var whitespace = (\n // whitespace\n ' \\t\\x0B\\f\\xA0\\ufeff' +\n\n // line terminators\n '\\n\\r\\u2028\\u2029' +\n\n // unicode category \"Zs\" space separators\n '\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\
...等等。请注意,您会看到不止一个版本的 sn-p。我刚刚在上面提到的那个新的 sn-p 中粘贴了lodash.js,而且我已经有两次了。
那么,如何真正从中获取脚本呢?好吧,一旦你得到 value 字段,那只是一个 JSON 数组,其中你有一个 sn-p id、name 和 content。因此,创建一个 SQL 脚本以从命令行传递给 sqlite3,如下所示:
echo "select value from ItemTable where key = 'scriptSnippets';" > showSnippets.txt
然后像这样喂那个脚本:
sqlite3 chrome-devtools_devtools_0.localstorage < showSnippets.txt
如果你这样做,看起来会更漂亮:
sqlite3 chrome-devtools_devtools_0.localstorage < showSnippets.txt | python -m json.tool
【讨论】:
苹果机
/Users/yourUserName/Library/Application Support/Google/Chrome/Default/Preferences
Chrome 将您的 sn-ps 保存在首选项中。
【讨论】:
编辑:此答案已过时,sn-ps 不再保存在本地存储中。
请参阅 paulirish's answer。
对于旧版本的 chrome,这可能有效。 它存储在这里 C:\Users\Webdev\AppData\Local\Google\Chrome\User Data\Default\Local Storage\chrome-devtools_devtools_0.localstorage。 但我不认为你可以从文件路径中查看它,
您可以通过执行以下操作来查看它。 打开 devtools,然后前往 chrome://inspect,在“其他”标题下,您应该会看到刚刚打开的 devtools 面板 url,该 url 以 chrome-devtools://dev 开头。 通过单击检查链接对其进行检查。 应该打开一个新的 devtools 窗口,在资源选项卡下,转到 localstorage 有一个 名为 scriptSnippets 的键,这就是它的保存位置。只需复制并粘贴它或使用控制台面板预先修改输出。
希望对你有帮助
【讨论】: