我想与我的同事共享一个未打包的扩展名。它chrome.runtime.sendMessage(string extensionId, any message, object options, function responseCallback)
在注入的脚本中使用该方法。为此,我需要提前知道扩展名。
在不同系统上,解压后的扩展程序的扩展程序ID是否会有所不同,或者我可以对在扩展程序菜单中找到的扩展程序进行硬编码吗?
虽然我链接到该问题,该问题解释了如何“固定”未打包扩展名的ID,这将解决OP面临的实际问题,但问题本身(如标题中所述)很有趣。
如果我们查看Chromium源,我们将看到ID只是扩展的绝对路径(可能是规范化的,无论什么意思)的SHA哈希。代码亮点:
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// chromium/src/chrome/browser/extensions/unpacked_installer.cc
int UnpackedInstaller::GetFlags() {
std::string id = crx_file::id_util::GenerateIdForPath(extension_path_);
/* ... */
}
// chromium/src/components/crx_file/id_util.cc
std::string GenerateIdForPath(const base::FilePath& path) {
base::FilePath new_path = MaybeNormalizePath(path);
std::string path_bytes =
std::string(reinterpret_cast<const char*>(new_path.value().data()),
new_path.value().size() * sizeof(base::FilePath::CharType));
return GenerateId(path_bytes);
}
std::string GenerateId(const std::string& input) {
uint8 hash[kIdSize];
crypto::SHA256HashString(input, hash, sizeof(hash));
std::string output =
base::StringToLowerASCII(base::HexEncode(hash, sizeof(hash)));
ConvertHexadecimalToIDAlphabet(&output);
return output;
}
因此,它仅应取决于扩展文件夹的绝对文件系统路径。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句